Reputation: 47
This issues is a bit of quirk - and it may be a systematic issue that just won't work. My overall project is that I need to have a presentation playing on loop 24/7 and it has some linked charts from an excel file that it needs to pull data from. I wrote the basic code to do this.
However when I first open PowerPoint and run the presentation -> No code is run (verified with Debug.Prints and MsgBoxes). However if I just open up the code in developer (But don't edit) and run the presentation, everything works as planned. I've turned all the Trust Center Security settings to allow all macros and setup my network files as automatically trusted as well. I've also verified that this occurs with another of the laptops here. Any help is greatly appreciated. For reference, this is my simple code that needs to run.
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
Upvotes: 1
Views: 3321
Reputation: 6433
Thanks for the opportunity. There are 3 main parts that can allow you to do that.
Solution:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="onLoadCode" >
</customUI>
onLoadCode
to do initialization.Ensure the Presentation is set to Kiosk mode for your purpose:
Class Module: 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
Module: Player
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
You should remove the Debug lines for production environment. Have fun!
Upvotes: 2