Undo Method [Visio 2003 SDK Documentation]

Reverses the most recent undo unit, if the undo unit can be reversed.

object**.Undo**

object     Required. An expression that returns an Application object.

Version added

2.0

Remarks

Use the Undo method to reverse actions one undo unit at a time.

The number of times that code can call the Undo method depends on whether or not the code is executing in the scope of an open undo unit. Code runs in the scope of an open undo unit if it is:

  • A macro or add-on invoked by the Microsoft Office Visio user interface.
  • In an event handler responding to a Visio event other than the VisioIsIdle event.
  • In a user-created undo scope.

If code is not executing in the scope of an open undo unit, it can call the Undo method for each undo unit presently on the Visio undo stack. The maximum number of units on the undo stack is set in the Options dialog box (Tools menu) on the General tab (20 is the default). If the number of calls to the Undo method exceeds the number of undo units on the stack, no action is taken and the Undo method raises no exception.

If code is executing in the scope of an open undo unit, it can call the Undo method once for each operation in the open undo unit. If there are additional calls to the Undo method, it raises an exception and takes no action. For example, if code in a macro performs two operations, it can call the Undo method twice. If the macro calls the Undo method a third time, the Undo method raises an exception.

Code that calls the Undo method from within the scope of an undo unit cannot call the Redo method to reverse the action. The Redo method can only be called when there are no open undo units.

The Undo method also raises an exception if the Visio instance is presently performing an undo or redo. To determine whether the Visio instance is undoing or redoing, use the IsUndoingOrRedoing property.

You can call the Undo method from the VisioIsIdle event handler because the VisioIsIdle event can only fire when the IsUndoingOrRedoing property is False. You can also call the Undo method from code not invoked by the Visio instance, for example, code invoked from the Visual Basic Editor or from an external program.

You can undo most actions, but not all. Use the Redo method to reverse the effect of the Undo method.

Example

This Microsoft Visual Basic for Applications (VBA) macro shows how to undo and redo actions.

Public Sub Undo_Example() 

    Dim vsoShape As Visio.Shape 

    'Draw a rectangle, use Undo to delete it, and
    'then use Redo to redraw it.
    Set vsoShape = ActivePage.DrawRectangle(1, 5, 5, 1)
 
    'Delete the shape. 
    Visio.Application.Undo 
    
    'Bring it back. 
    Visio.Application.Redo 

End Sub  
    

Applies to | Application object | InvisibleApp object

See Also | AddUndoUnit method | BeginUndoScope method | EndUndoScope method | IsInScope property | IsUndoingOrRedoing property | PurgeUndo method | Redo method | VisioIsIdle event