Document.Undo 方法 (2007 system)

更新:2007 年 11 月

撤消上一个操作或者一系列操作,这些操作显示在“撤消”列表中。如果操作已成功撤消,则返回 true。

命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word.v9.0(在 Microsoft.Office.Tools.Word.v9.0.dll 中)

语法

声明
Public Function Undo ( _
    ByRef Times As Object _
) As Boolean
用法
Dim instance As Document
Dim Times As Object
Dim returnValue As Boolean

returnValue = instance.Undo(Times)
public bool Undo(
    ref Object Times
)

参数

  • Times
    类型:System.Object%

    要撤消的操作的数目。默认设置是撤消上一个操作。

返回值

类型:System.Boolean

如果操作已成功撤消,则为 true。

备注

可选参数

有关可选参数的信息,请参见了解 Office 解决方案中的可选参数

示例

下面的代码示例向当前文档添加一行文本,然后显示一个消息框,询问是否移除该文本。如果您单击“确定”,则该示例使用 Undo 方法移除文本。

此示例针对的是文档级自定义项。

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);
    }
}

权限

另请参见

参考

Document 类

Document 成员

Microsoft.Office.Tools.Word 命名空间