这是一个棘手而有趣的问题,我承认这是大部分的解决方案,但有一个缺失的部分。我没有在 Powerpoint 中做过很多编程,所以这是一个挑战。当您打开 VBE 时,没有任何可用的模块、类或对象。这与 Word 和 Excel 完全不同。这意味着我们都靠自己...
我创建了一个包含五张幻灯片的演示文稿。在第三张幻灯片上,我插入了一些对象,看起来像这样:
对于 VBA 部分,我必须学习的第一件事是创建一个class module that will catch all of the events for the presentation。我非常简单的类叫做EventClassModule,看起来像这样:
Option Explicit
Public WithEvents App As Application
Private Sub App_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
If Wn.View.CurrentShowPosition = 3 Then
UpdateTheCount Wn.View.Slide
End If
End Sub
所以现在在一个常规模块中,你必须运行一些东西来创建这个类并将其初始化为一个全局对象。
Option Explicit
Dim eventClass As EventClassModule
Sub InitializeApp()
Set eventClass = New EventClassModule
Set eventClass.App = Application
End Sub
在我的测试中,我只是手动运行InitializeApp 过程来创建全局对象。 这是我的解决方案中缺少的部分... - 我不知道如何自动运行此初始化来创建对象。也许是一个功能区按钮?
然后,在常规代码模块中也是更新文本框的过程:
Public Sub UpdateTheCount(ByRef thisSlide As Slide)
'--- loop through all the shapes to find the correct textbox,
' then update the value for display
Const LABEL_TEXT As String = "Value to update:"
Dim shp As Shape
For Each shp In thisSlide.Shapes
If shp.Type = msoTextBox Then
Dim theText As String
theText = shp.TextFrame.TextRange.Text
If InStr(1, theText, LABEL_TEXT, vbTextCompare) = 1 Then
Dim colonPos As Long
Dim theValue As Long
colonPos = InStr(1, theText, ":", vbTextCompare)
theValue = CLng(Right$(theText, Len(theText) - colonPos))
theValue = theValue + 1
theText = LABEL_TEXT & " " & theValue
shp.TextFrame.TextRange.Text = theText
End If
End If
Next shp
End Sub
一旦您的代码就位并且您手动运行了InitializeApp() 子程序,只需开始幻灯片放映(并且可能将其设置为从结尾处循环播放)并逐步进行。文本框的值会自动更新和递增。
我有兴趣从有这种经验的人那里学习如何自动启动它。