如何刷新幻灯片放映中的活动幻灯片?

问题描述 投票:0回答:3

基于我的上一个问题我得到了正确的代码来更改形状的图像。
不幸的是,这不会更新活动演示文稿。如果我关闭演示文稿并重新启动它,图像就会更改,但更改应该是直接可见的。

这是我更改图像的代码:

ActivePresentation.SlideShowWindow.View.Slide.Shapes("SolutionA_Image").Fill.UserPicture ("D:\User\SolutionWrong.jpg")

我找到了一种更新演示文稿的方法,但这会让演示文稿闪烁。

ActivePresentation.SlideShowWindow.Height = ActivePresentation.SlideShowWindow.Height - 1
ActivePresentation.SlideShowWindow.Height = ActivePresentation.SlideShowWindow.Height + 1

编辑
我尝试按照here的建议刷新幻灯片,但这对我不起作用。

Dim lSlideIndex As Long
lSlideIndex = SlideShowWindows(1).View.CurrentShowPosition
SlideShowWindows(1).View.GotoSlide lSlideIndex

编辑2
我上传了我的文件:下载

vba powerpoint
3个回答
3
投票

最后我在这篇博文中找到了答案。这似乎是 PowerPoint 2007 中的一个错误。

此代码有助于修复错误:

Dim osld As Slide
'get current slide
Set osld = ActivePresentation.SlideShowWindow.View.Slide
'the next line adds the empty textbox and refreshs the slide
osld.Shapes.AddTextbox msoTextOrientationHorizontal, 1, 1, 1, 1

3
投票

我也在我的Power Point中发现了这个错误, 我将这一行添加到代码中,它修复了错误

Application.SlideShowWindows(1).View.GotoSlide Me.SlideIndex


0
投票

我无意中发现每次按任意键盘键时动画图像(在我的例子中为 GIF)都会更新(PowerPoint 2010)。我尝试使用 SendKeys 来模仿这种行为,现在我的图像正在更新。

请注意,在我的情况下,仅 DoEvents 不起作用,并且所有 GIF 仅在 VBA 脚本执行完成后才播放。这是我当前使用 SendKeys 和 DoEvents 的解决方案。仅当当前幻灯片包含动画图像时,我才将 gifUpdate 设置为 True。

Const gifUpdate As Boolean = True
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 

Sub myDelay(cnt As Long) ' 1000/30fps=33ms
    Dim i As Long: For i = 1 To cnt
        Sleep 33
        If gifUpdate Then SendKeys "+", True
        DoEvents
        
        Sleep 33
        If gifUpdate Then SendKeys "+", True
        DoEvents
        
        Sleep 33
        If gifUpdate Then SendKeys "+", True
        DoEvents

    Next
End Sub

“+”表示shift键,其他键码可以在这里找到: https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/sendkeys-statement

© www.soinside.com 2019 - 2024. All rights reserved.