首页 文章

在powerpoint中更改幻灯片时如何运行vba代码?

提问于
浏览
0

当我更换幻灯片时,我正在尝试重置某些文本框和标签的内容,但我很难让它工作 . 经过大量的谷歌搜索和搜索后,我想出了这个,但似乎没有用 . 我正在尝试使用PowerPoint 2013和2016中的OnSlideShowPageChange事件,但似乎没有任何效果 . 我不习惯使用PowerPoint vba,所以我可能会做一些完全错误的事情 .

Edit: I've managed to find an alternative method of resetting the label text. I've managed to get it to reset when the user focuses on one of the text boxes or moves their mouse over the label. But, I'm still curious to know the answer to this question; I'm not sure why my code isn't working.

如果有人能指出任何问题以及如何解决这些问题,我会很高兴 .

这是我到目前为止所得到的:

Public Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)
    Dim Sld As Slide

    If Wn.View.CurrentShowPosition = 9 Then
        'Perform Updates for slide #9
        Set Sld = Application.ActivePresentation.Slides(9)
        Sld.Shapes(TextBox_Form_Name).TextFrame.TextRange.Text = ""
        Sld.Shapes(TextBox_Form_Email).TextFrame.TextRange.Text = ""
        Sld.Shapes(TextBox_Form_Message).TextFrame.TextRange.Text = ""
        Sld.Shapes(Label_Form_Info).TextFrame.TextRange.Text = ""
    End If

    If Wn.View.CurrentShowPosition = 18 Then
        'Perform Updates for slide #18
        Set Sld = Application.ActivePresentation.Slides(18)
        Sld.Shapes(TextBox_Form_Name).TextFrame.TextRange.Text = ""
        Sld.Shapes(TextBox_Form_Email).TextFrame.TextRange.Text = ""
        Sld.Shapes(TextBox_Form_Message).TextFrame.TextRange.Text = ""
        Sld.Shapes(Label_Form_Info).TextFrame.TextRange.Text = ""
    End If
End Sub

我也尝试将形状名称放在语音标记中,但这似乎没有帮助 .

顺便说一句,我需要代码在PowerPoint 2013和2016中都可以使用 .

1 回答

  • 0

    以下是PowerPoint常见问题解答中的答案http://www.pptfaq.com

    假设您的代码依赖于OnSlideShowPageChange(SHW as SlideshowWindow)事件,当从VBA内部运行或从PowerPoint中启动演示文稿时有效,但是当您通过双击PPS或PPSM的图标来启动演示时则不行 . 幻灯片放映正常启动,但OnSlideShowPageChange子例程中的代码永远不会运行 .

    解决方案在第一张幻灯片上添加一个Active-X控件(来自“开发人员”选项卡)(如果您不想在幻灯片放映期间看到它,请将其拖离幻灯片) .

    这会强制VBA在演示文稿启动时进行初始化,因此会触发事件并运行代码 .

相关问题