Document.Undo Method (Publisher)
Undoes the last action or a specified number of actions. Corresponds to the list of items that appears when you click the arrow beside the Undo button on the Standard toolbar.
The following example uses the Undo method to undo actions that do not meet specific criteria.
Part 1 of the example adds a rectangular callout shape to the fourth page of the active publication, and text is added to the callout. This process creates three actions.
Part 2 of the example tests whether the font of the text added to the callout is Verdana. If not, then the Undo method is used to undo all available actions (the value of the UndoActionsAvailable property is used to specify that all actions be undone). This clears all actions from the stack. A new rectangle shape and text frame are then added and the text frame is populated with Verdana text.
Dim thePage As page Dim theShape As Shape Dim theDoc As Publisher.Document Set theDoc = ActiveDocument Set thePage = theDoc.Pages(4) With theDoc ' Part 1 With thePage ' Setting the shape creates the first action Set theShape = .Shapes.AddShape(msoShapeRectangularCallout, _ 75, 75, 120, 30) ' Setting the text range creates the second action With theShape.TextFrame.TextRange ' Setting the text creates the third action .Text = "This text is not Verdana." End With End With ' Part 2 If Not thePage.Shapes(1).TextFrame.TextRange.Font.Name = "Verdana" Then ' UndoActionsAvailable = 3 .Undo (.UndoActionsAvailable) With thePage Set theShape = .Shapes.AddShape(msoShapeRectangle, _ 75, 75, 120, 30) With theShape.TextFrame.TextRange .Font.Name = "Verdana" .Text = "This text is Verdana." End With End With End If End With