Create multiple undo entries for automated code
Let us see how to make use StartUndoNewEntry to create entries in the undo stack while the macro runs. Normally when the macro execution ends you wind up with just one entry in the undo stack for the operations that were executed while the macro was executed. Using this new property you can define the points at which a new entry should appear in the undo stack available in the UI.
In the example below I make call the method to make the the macro edits appear as logical chunks in the Undo stack. Once the macro is run, check the Undo button in the PowerPoint UI.
Supported versions: PowerPoint 2010+
' -------------------------------------------------------------------------------- ' Copyright ©1999-2018, Shyam Pillai, All Rights Reserved. ' -------------------------------------------------------------------------------- ' You are free to use this code within your own applications, add-ins, ' documents etc but you are expressly forbidden from selling or ' otherwise distributing this source code without prior consent. ' This includes both posting free demo projects made from this ' code as well as reproducing the code in text or html format. ' --------------------------------------------------------------------------------Sub UseStartNewUndoEntry() Dim shp As Shape Application.StartNewUndoEntry Set shp = ActiveWindow.Selection.SlideRange(1).Shapes.AddShape(msoShapeRectangle, 10, 10, 200, 100) Application.StartNewUndoEntry shp.TextFrame2.TextRange.Text = "Sample test" shp.Fill.Visible = True Call shp.Fill.OneColorGradient(msoGradientDiagonalUp, 1, 0) Application.StartNewUndoEntry shp.Line.Style = msoLineThickThin shp.Line.ForeColor.RGB = RGB(0, 0, 255) End Sub |
Copyright 1999-2018 (c) Shyam Pillai. All rights reserved.