Hello all,
I currently have an Excel spreadsheet that uses a timer to automatically runs code that populates two charts, copy and pastes those charts as pictures into new slides in a PowerPoint presentation, and then starts a slide show.
The issue I'm having is that when the timer triggers the code to run again, I get an error (Run-time error, Application: Invalid request) because the slide show is still running. Is there a way that I can use some kind of if/then statement to find out if a slide show is currently running then exit out of the slide show?
Below is the code of the module that is giving the error.
Thanks for any help. This site has been immensely helpful with all of my VBA problems.
I currently have an Excel spreadsheet that uses a timer to automatically runs code that populates two charts, copy and pastes those charts as pictures into new slides in a PowerPoint presentation, and then starts a slide show.
The issue I'm having is that when the timer triggers the code to run again, I get an error (Run-time error, Application: Invalid request) because the slide show is still running. Is there a way that I can use some kind of if/then statement to find out if a slide show is currently running then exit out of the slide show?
Below is the code of the module that is giving the error.
Thanks for any help. This site has been immensely helpful with all of my VBA problems.
Code:
Sub ChartToPresentation()
' Uses Early Binding to the PowerPoint Object Model
' Set a VBE reference to Microsoft PowerPoint Object Library
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim SlideCount As Long
Dim iCht As Integer
Dim x As Long
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
' ****************************************
' An error occurs at the next line of code
' ****************************************
PPApp.ActiveWindow.ViewType = ppViewSlide
If PPPres.Slides.Count <> 0 Then
For x = PPPres.Slides.Count To 1 Step -1
PPPres.Slides(x).Delete
Next x
End If
For iCht = 1 To ActiveSheet.ChartObjects.Count
' copy chart as a picture
ActiveSheet.ChartObjects(iCht).Chart.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
' Add a new slide and paste in the chart
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutBlank)
PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex
With PPSlide
' paste and select the chart picture
.Shapes.Paste.Select
' align the chart
PPApp.ActiveWindow.Selection.ShapeRange.Width = 720
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
End With
With PPSlide.SlideShowTransition
.Speed = ppTransitionSpeedSlow
.EntryEffect = ppEffectFadeSmoothly
.AdvanceOnTime = msoTrue
.AdvanceTime = 12
End With
Next
PPPres.SlideShowSettings.Run
' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Sub