指定要将其合并以创建单项撤消操作的一组操作的起始点和标签(文字说明)。
可以使用 EndCustomUndoAction 方法指定用于创建单项撤消操作的操作结束点。 可以使用单项撤消操作将合并的操作组撤消。
语法
表达式。BeginCustomUndoAction (ActionName)
表达式 表示 Document 对象的变量。
参数
| 名称 | 必需/可选 | 数据类型 | 说明 |
|---|---|---|---|
| ActionName | 必需 | String | 对应于单个撤消操作的标签。 当您选取 Standard 工具栏上“撤消”按钮旁边的箭头时,此标签将显示。 |
备注
下列 文档 对象的方法将一个自定义撤消操作中不可用。 如果下列任一方法调用的自定义撤消操作中,则会返回运行时错误:
- Close
- MailMerge.DataSource.Close
- PrintOut
- Redo
- Save
- SaveAs
- Undo
- UndoClear
- UpdateOLEObjects
调用 EndCustomUndoAction 方法之前,必须调用 BeginCustomUndoAction 方法。 如果 EndCustomUndoAction 在 BeginCustomUndoAction 之前调用,则返回运行时错误。
尽管允许在一个自定义撤消操作中嵌套另一个自定义撤消操作,但是嵌套的自定义撤消操作不起作用。 只有最外面的自定义撤消操作才会被激活。
示例
下面的示例包含两个自定义撤消操作。 第一个是在当前出版物的第一页上创建的。 BeginCustomUndoAction 方法用于指定何时开始执行自定义撤消操作的点。 六个单个操作执行,然后包装成通过 EndCustomUndoAction 调用一个操作。
然后测试在第一个自定义撤消操作中创建的文本框架中的文字,以确定字体是否为 Verdana。 如果不是,则调用 Undo 方法,并将 UndoActionsAvailable 作为参数进行传递。 在这种情况下,只有一个撤消操作可用。 因此,对撤 销 方法的调用仅撤消一个操作,但此一个操作已将六个操作包装为一个。
然后创建第二个撤消操作,并且还可以在以后使用单个撤消操作将其撤消。
Dim thePage As page
Dim theShape As Shape
Dim theDoc As Publisher.Document
Set theDoc = ActiveDocument
Set thePage = theDoc.Pages(1)
With theDoc
' The following six actions are wrapped to create one
' custom undo action named "Add Rectangle and Courier Text".
.BeginCustomUndoAction ("Add Rectangle and Courier Text")
With thePage
Set theShape = .Shapes.AddShape(msoShapeRectangle, _
75, 75, 190, 30)
With theShape.TextFrame.TextRange
.Font.Size = 14
.Font.Bold = msoTrue
.Font.Name = "Courier"
.Text = "This font is Courier."
End With
End With
.EndCustomUndoAction
If Not thePage.Shapes(1).TextFrame.TextRange.Font.Name = "Verdana" Then
' This call to Undo will undo all actions that are available.
' In this case, there is only one action that can be undone.
.Undo (.UndoActionsAvailable)
' A new custom undo action is created with a name of
' "Add Balloon and Verdana Text".
.BeginCustomUndoAction ("Add Balloon and Verdana Text")
With thePage
Set theShape = .Shapes.AddShape(msoShapeBalloon, _
75, 75, 190, 30)
With theShape.TextFrame.TextRange
.Font.Size = 11
.Font.Name = "Verdana"
.Text = "This font is Verdana."
End With
End With
.EndCustomUndoAction
End If
End With
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。