在 PowerPoint 中结束宏中的撤消事务

发布于 2024-12-17 11:22:34 字数 875 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执手闯天涯 2024-12-24 11:22:34

如果将 ExecuteMso 行替换为此行,则整个过程仍然是一个撤消:

ActiveWindow.Selection.ShapeRange.TextEffect.FontBold = msoTrue

更新

如果您使用的是 PowerPoint 2010 或更高版本,请将此行放在您要删除的每个代码块之前。希望用户能够一次撤消一个步骤:

Application.StartNewUndoEntry

If you replace the ExecuteMso line with this one, the entire procedure remains one Undo:

ActiveWindow.Selection.ShapeRange.TextEffect.FontBold = msoTrue

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:

Application.StartNewUndoEntry
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文