Document.Undo Method (2007 System)

Undoes the last action or a sequence of actions, which are displayed in the Undo list. Returns true if the actions were successfully undone.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)

Syntax

'Declaration
Public Function Undo ( _
    ByRef Times As Object _
) As Boolean
'Usage
Dim instance As Document 
Dim Times As Object 
Dim returnValue As Boolean 

returnValue = instance.Undo(Times)
public bool Undo(
    ref Object Times
)
public:
bool Undo(
    Object^% Times
)
public function Undo(
    Times : Object
) : boolean

Parameters

  • Times
    Type: System.Object%

    The number of actions to be undone. The default is to undo the last action.

Return Value

Type: System.Boolean
true if the actions were successfully undone.

Remarks

Optional Parameters

For information on optional parameters, see The Variable missing and Optional Parameters in Office Solutions.

Examples

The following code example adds a line of text to the current document and then displays a message box that asks whether to remove the text. If you click OK, then the example uses the Undo method to remove the text.

This example is for a document-level customization.

Private Sub DocumentUndo()
    Me.Range(0, 0).Text = "A line of text" 
    If DialogResult.OK = MessageBox.Show( _
        "Would you like to undo the text insertion?", "Test", _
        MessageBoxButtons.OK) Then 

        Me.Undo(1)
    End If 
End Sub
private void DocumentUndo()
{
    string newText = "A line of text";
    object start = 0;
    object end = 0;
    Word.Range range1 = this.Range(ref start, ref end);
    range1.Text = newText;

    if (DialogResult.OK == MessageBox.Show(
        "Would you like to undo the text insertion?", "Test", 
        MessageBoxButtons.OK))
    {
        object Times = 1;
        this.Undo(ref Times);
    }
}

.NET Framework Security

See Also

Reference

Document Class

Document Members

Microsoft.Office.Tools.Word Namespace