这个问题有些怪癖 - 这可能是一个系统性的问题,只是不会起作用。我的整个项目是我需要在循环播放24/7循环播放,它有一些excel文件的链接图表,它需要从中提取数据。我写了基本代码来做到这一点。
然而,当我第一次打开PowerPoint并运行演示文稿时 - >没有运行代码(使用Debug.Prints和MsgBoxes验证)。但是,如果我只是在开发人员中打开代码(但不要编辑)并运行演示文稿,一切都按计划进行。我已将所有信任中心安全设置都设置为允许所有宏并将我的网络文件设置为自动受信任。我还证实这种情况发生在这里的另一台笔记本电脑上。任何帮助是极大的赞赏。作为参考,这是我需要运行的简单代码。
Sub updateCharts()
Dim i As Integer
Dim sld As Slide
Dim shp As Shape
If IsFileOpen(filePath) = False Then
If ActivePresentation.SlideShowWindow.View.Slide.SlideIndex = 1 Then
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasChart Then
On Error Resume Next
shp.LinkFormat.Update
shp.Chart.Refresh
On Error GoTo 0
End If
Next shp
Next sld
End If
End If
End Sub
Sub OnSlideShowPageChange(ByVal Win As SlideShowWindow)
Call updateCharts
End Sub
答案 0 :(得分:1)
谢谢你的机会。有3个主要部分可以让你这样做。
解决方案:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="onLoadCode" >
</customUI>
onLoadCode
进行初始化。确保将演示文稿设置为Kiosk模式以用于您的目的:
课程模块: EventClassModule
Public WithEvents App As Application
Private Sub App_SlideShowBegin(ByVal Wn As SlideShowWindow)
Debug.Print Now & vbTab & "App_SlideShowBegin"
updateCharts Wn
End Sub
Private Sub App_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
Debug.Print Now & vbTab & "App_SlideShowNextSlide"
updateCharts Wn
End Sub
模块:播放器
Dim X As New EventClassModule
Sub OnLoadCode()
InitializeApp
End Sub
Sub InitializeApp()
Set X.App = Application
ActivePresentation.SlideShowSettings.Run
End Sub
Sub updateCharts(ByRef Win As SlideShowWindow)
Dim sld As Slide
Dim shp As Shape
Debug.Print Now & vbTab & "Playing slide with index: " & Win.View.Slide.SlideIndex
If Win.View.Slide.SlideIndex = 1 Then
Debug.Print Now & vbTab & "Update charts on other slides!"
For Each sld In Win.Presentation.Slides
For Each shp In sld.Shapes
If shp.HasChart Then
Debug.Print Now & vbTab & "Update chart """ & shp.Chart.Name & """ on slide index " & sld.SlideIndex
On Error Resume Next
shp.LinkFormat.Update
shp.Chart.Refresh
If Err.Number <> 0 Then
Debug.Print Now & vbTab & "ERR(" & Err.Number & ") " & Err.Description
Err.Clear
End If
On Error GoTo 0
End If
Next
Next
End If
End Sub
您应该删除生产环境的调试行。玩得开心!