Whait is the purpose of the BeginUndoScop Method

Started by Miguel, February 10, 2017, 10:27:22 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Miguel

Hello!

I would like to know what is the purpose of the BeginUndoScope method. I have sometimes this method when I am recording a macro.

Thank you for your help!

Surrogate

#1
your recorded macro can contain a lot of actions.
you can cancel these actions just press keys Ctlr+Z or press Undo button.
This method allow cancel all actions at once, not step by step!

Nikolay

Some illustrations to the Surrogate's answer. Suppose you have this function:

Sub Macro1()
   ActivePage.DrawRectangle 0,0,1,1
   ActivePage.DrawRectangle 1,1,2,2
   ActivePage.DrawRectangle 2,2,3,3
End Sub

After executing it, you will have 3 undo items (see picture below)

Alternatively, with BeginUndoScope/EndUndoScope, you'll see only 1 item
And all three operations will be undone when you click it.

Sub Macro1()
   scope = Application.BeginUndoScope("Adding some rectangles")
        ActivePage.DrawRectangle 0, 0, 1, 1
        ActivePage.DrawRectangle 1, 1, 2, 2
        ActivePage.DrawRectangle 2, 2, 3, 3
   Application.EndUndoScope scope, True
End Sub


Miguel

#3
I understand!

Thank you for your explanations Nikolay and surrogate! But I don't understand why we have this method when I am recording a macro. there is other purpose ?