我正在尝试在PowerPoint中创建一个计时器。我编写了一个代码来通过VBA循环来改变形状的文本。在演示模式中,我只看到第一个和最后一个变化。中间的更改在屏幕上不可见。有没有办法在每次更改后刷新对象?请帮忙
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Test()
ActivePresentation.Slides(2).Shapes(1).TextFrame.TextRange.Text = 0
For i = 0 To 5
Sleep (1000)
ActivePresentation.Slides(2).Shapes(1).TextFrame.TextRange.Text = i
Next
End Sub
答案 0 :(得分:1)
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Test()
With ActivePresentation
.Slides(2).Shapes(1).TextFrame.TextRange.Text = 0
For i = 0 To 5
Sleep (1000)
.Slides(2).Shapes(1).TextFrame.TextRange.Text = i
RefreshSlide .SlideShowWindow
Next i
End With 'ActivePresentation
End Sub
此例程即时更新幻灯片
如果它不适合您,请取消注释Adds an empty textbox
Public Sub RefreshSlide(ByVal SlideShowWindowObject As Object)
With SlideSlideShowWindowObject
.Height = .Height - 1
.Height = .Height + 1
'Adds an empty textbox
'.View.Slide.Shapes.AddTextbox msoTextOrientationHorizontal, 1, 1, 1, 1
End With 'SlideSlideShowWindowObject
End Sub
答案 1 :(得分:0)
以防万一它可能对某人有所帮助,我编写了此例程来更新演示文稿中每张幻灯片上的日期。每张幻灯片上都必须有同名的对象(我的只是简单地命名为“SlideDate”),否则会失败。你可以隐藏对象,代码仍然可以工作。只需根据您拥有的幻灯片数量更新 For 循环并调整您的对象名称。它也会更新隐藏的幻灯片。
Sub ChangeFooterDates()
Dim SlideDate As String
SlideDate = "2/22/21"
With ActivePresentation
For n = 1 To 25
.Slides(n).Shapes("SlideDate").TextFrame.TextRange.Text = SlideDate
Next n
End With 'ActivePresentation
End Sub