在 PowerPoint 中结束宏中的撤消事务
如 http://support.microsoft.com/kb/278591 中所述,PowerPoint 通常会将所有宏或加载项对单个撤消步骤所做的更改。因此,如果将以下代码放入 VBA 中并按 F5 执行两次 仅是一个撤消步骤。
Sub Move()
If ActiveWindow.Selection.Type = ppSelectionShapes Then
ActiveWindow.Selection.ShapeRange.IncrementLeft 10
End If
End Sub
我正在寻找一种方法来在更复杂的场景中更改此行为,在这种场景中,用户可以在不直接访问 PowerPoint 的情况下进行多项更改。理想情况下,从用户的角度来看,应该可以撤消与一个更改相对应的一组修改。
我发现 ExecuteMso 似乎破坏了撤消事务。因此,如果执行以下代码两次,则会导致 4 个撤消步骤(第一次增量,ExecuteMso,第二次增量,ExecuteMso)。
Sub Move()
If ActiveWindow.Selection.Type = ppSelectionShapes Then
ActiveWindow.Selection.ShapeRange.IncrementLeft 10
Application.CommandBars.ExecuteMso "Bold"
End If
End Sub
有人知道问题的真正解决方案或更好的解决方法吗?虽然我没有找到,也许有一个可以将Word或Excel移植到PowerPoint的解决方案?
As described in http://support.microsoft.com/kb/278591 PowerPoint will usually combine all changes that a macro or add-in makes to a single undo step. So if you put the following code into VBA and execute it twice by pressing F5 there
will only be one undo step.
Sub Move()
If ActiveWindow.Selection.Type = ppSelectionShapes Then
ActiveWindow.Selection.ShapeRange.IncrementLeft 10
End If
End Sub
I am looking for a way to change this behavior in a more complex scenario where the user can make multiple changes without directly accessing PowerPoint. Ideally, it should be possible to undo a set of modifications that corresponds to one change from the user's perspective.
What I found out is that ExecuteMso seems to break the undo transaction. So if you execute the following code twice it results in 4 undo steps (first increment, ExecuteMso, second increment, ExecuteMso).
Sub Move()
If ActiveWindow.Selection.Type = ppSelectionShapes Then
ActiveWindow.Selection.ShapeRange.IncrementLeft 10
Application.CommandBars.ExecuteMso "Bold"
End If
End Sub
Anyone knows a real solution for the problem or a better workaround? Although I didn't find it maybe there is a solution for Word or Excel that can be ported to PowerPoint?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将
ExecuteMso
行替换为此行,则整个过程仍然是一个撤消:更新
如果您使用的是 PowerPoint 2010 或更高版本,请将此行放在您要删除的每个代码块之前。希望用户能够一次撤消一个步骤:
If you replace the
ExecuteMso
line with this one, the entire procedure remains one Undo:Update
If you are using PowerPoint 2010 or later put this line before each block of code that you want the user to be able to undo a step at a time: