在 PowerPoint VBA 循环中更改形状文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44106871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change shape text in PowerPoint VBA loop
提问by Ramyaa Seetharaman
I'm trying to create a timer in PowerPoint. I have written a code to change the text of the shape through VBA loop. In the presentation mode I see only the first and last change. In-between changes are not visible on screen. Is there a way to refresh the object after every change? Please help
我正在尝试在 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
回答by R3uK
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
This routine update the slide on the fly.
If it doesn't work for you, uncomment the line below Adds an empty textbox
此例程动态更新幻灯片。
如果它不适合您,请取消注释下面的行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