VBA auto-macro OnSlideShowPageChange crashing PowerPoint

I am having to use the dreaded OnSlideShowPageChange event (instead of the application events object) in a project that needs to be compatible with both PC and Mac versions of PowerPoint. The macro has to detect when a slide show starts and then add certain objects to all slides, deleting them again when the slide show ends. To do this, I am using the OnSlideShowPageChange event to detect when the slide show starts, exit the show, add the objects to the slides in the normal view before restarting the show. Everything is working as expected but the OnSlideShowPageChange macro crashes as it exits (I put a break point on the End Sub line which it reaches without error and then crashes as I step into it).

#If Mac Then
Public IgnoreEvents As Boolean
Public ObjectsExist As Boolean
Public Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)
  If Not IgnoreEvents And Not ObjectsExist Then
    IgnoreEvents = True
    SlideShowWindows(1).View.Exit
    AddSlideObjects ' This procedure adds some shapes to each slide in the deck and is working as expected
    ActivePresentation.SlideShowSettings.Run
    IgnoreEvents = False
  End If
End Sub

Public Sub OnSlideShowTerminate(ByVal Wn As SlideShowWindow)
  If Not IgnoreEvents Then
    DeleteSlideObjects ' This procedure deletes the added shapes from each slide in the deck and is working as expected
  End If
End Sub
#End If

Open in new window


Any idea why the OnSlideShowPageChange procedure is crashing PowerPoint as it exists?
LVL 14
Jamie GarrochPowerPoint Consultant & DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jamie GarrochPowerPoint Consultant & DeveloperAuthor Commented:
I simplified the example to show how easy PowerPoint crashes. This is the full project code:

Option Explicit

Public IgnoreEvents As Boolean

Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)
  If Not IgnoreEvents Then
    IgnoreEvents = True
    Wn.View.Exit
    ActivePresentation.SlideShowSettings.Run
    IgnoreEvents = False
  End If
End Sub

Open in new window

0
Jamie GarrochPowerPoint Consultant & DeveloperAuthor Commented:
Or the even simpler way to crash PowerPoint:

Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)
  MsgBox "click OK to exit"
  Wn.View.Exit
End Sub

Open in new window

0
JSRWilsonCommented:
Not sure this works on a Mac but try:

Insert a UserForm

In the Activate event
Exit the show unload itself
Private Sub UserForm_Activate()
ActivePresentation.SlideShowWindow.View.Exit
Unload Me
End Sub

Open in new window


In OnSlideShowPageChange the code should show the form non modal

UserForm1.Show(vbmodeless)
1
Jamie GarrochPowerPoint Consultant & DeveloperAuthor Commented:
I like the thought process JSRWilson. Result is that it crashes PowerPoint:mac 2011. I couldn't test the preview of 2016:mac (which also crashes when using OnSlideShowPageChange to directly exit the slide show) because it appears to be impossible to insert a form but it appears that VBA is the same version in preview 15.11.2
0
JSRWilsonCommented:
I didn't test on a Mac (I have an old Snow Leopard  MacBook Pro now!) but it works on a PC. As  you already know OnSlideShowPageChange is unsupported code and a bit strange. I don't know if anyone understands how it is linked to the show window these days but it seems to need it. So if you use it to close the window it needs .... &**!*& (Unscientific explanation probably based on black magic)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft PowerPoint

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.