Vba 撤消命令工作到这么晚

Vba 撤消命令工作到这么晚,vba,powerpoint,undo,Vba,Powerpoint,Undo,我正在尝试删除带有动画的形状,以便在没有它们的情况下拍摄幻灯片打印屏幕。在那之后,我想要它们回来,所以我使用Undo命令。问题是这个命令工作到很晚。我的意思是,当我所有的vba代码结束时,它会执行撤消操作,我需要它在调用命令时执行。我试图停止代码几秒钟,但不起作用。以下是我正在使用的代码: For Each sl In ActivePresentation.Slides shapeNum = sl.Shapes.count 'ActivePresentatio

我正在尝试删除带有动画的形状,以便在没有它们的情况下拍摄幻灯片打印屏幕。在那之后,我想要它们回来,所以我使用Undo命令。问题是这个命令工作到很晚。我的意思是,当我所有的vba代码结束时,它会执行撤消操作,我需要它在调用命令时执行。我试图停止代码几秒钟,但不起作用。以下是我正在使用的代码:

  For Each sl In ActivePresentation.Slides
        shapeNum = sl.Shapes.count
        'ActivePresentation.Slides(1).Shapes(1).
        While shapeNum <> 0
            If sl.Shapes(shapeNum).AnimationSettings.Animate = msoTrue Then
                animationNum = animationNum + 1
                sl.Shapes(shapeNum).Delete
                animationNum = animationNum + 1
            End If
            shapeNum = shapeNum - 1
        Wend
   Next

   ActivePresentation.SaveAs "c:\dink_template\created_files", ppSaveAsPNG, msoTrue

   If animationNum <> 0 Then
        Application.CommandBars.ExecuteMso "Undo"
        'to make the code stop for 5 seconds
        waitTime = 5
        Start = Timer
        While Timer < Start + waitTime
        Wend
   End If
   ' Here the code continues doing several things
ActivePresentation.Slides中每个sl的

shapeNum=sl.Shapes.count
'活动演示文稿。幻灯片(1)。形状(1)。
而shapeNum 0
如果sl.Shapes(shapeenum).AnimationSettings.Animate=msoTrue,则
animationNum=animationNum+1
sl.Shapes(shapeenum).删除
animationNum=animationNum+1
如果结束
shapeNum=shapeNum-1
温德
下一个
ActivePresentation.SaveAs“c:\dink\U模板\创建的\U文件”,ppSaveAsPNG,msoTrue
如果animationNum为0,则
Application.CommandBars.ExecuteMso“撤消”
'使代码停止5秒钟
等待时间=5
开始=计时器
当定时器<开始+等待时间
温德
如果结束
“在这里,代码继续做一些事情
我还尝试使用MsgBox或其他方法来停止我在这里看到的内容:


但是什么都不起作用它会停留5秒钟什么都不做但是撤销在我完成代码之前不会起作用。有效的方法是使用调试器。如果我用调试器停止它,它会工作,但我想不使用调试器,因为当我把代码作为宏时,我将无法使用它

好了,伙计们,我想我找到了解决办法。只是在Application.commandbar.ExecuteMso“Undo”之后使用DoEvents,这就解决了问题。至少希望这会对某人有所帮助