(Solved) – using VBA to change zorder resets slide animations

  • by
(solved)-–-using-vba-to-change-zorder-resets-slide-animations

I am trying to create a level-based game in PowerPoint where each level is contained within one slide. On each level, I have a switch that changes the appearance of the slide by running a macro to swap the z-order of the slide’s shapes. However, whenever I do this, it resets the audio and animations that play automatically at the beginning of the slide. This defeats the purpose of me using one slide per level.

original level layout

level layout after macro

.

I found a similar question about this, but it only discusses how to activate animations from VBA, NOT how to sustain them. I am pretty new to VBA, and coding in general, so if anyone has any solutions or alternatives, I would greatly appreciate it!

Sub flipH1()

Dim mySld As Slide
Dim state As TextRange

Set mySld = ActivePresentation.Slides(SlideShowWindows(1).View.CurrentShowPosition)
Set state = mySld.Shapes("Flip State").TextFrame.TextRange


'This flips the level to the 'Horizonal Flip' position.
If state = "O" Then

With mySld.Shapes("foreO")
.ZOrder msoSendToBack
End With

With mySld.Shapes("backO")
.ZOrder msoSendToBack
End With

With mySld.Shapes("foreH")
.ZOrder msoBringToFront
End With

With mySld.Shapes("backH")
.ZOrder msoBringForward
End With

state = "H"


'This flips the level to the 'Original' position.
ElseIf state = "H" Then

With mySld.Shapes("foreH")
.ZOrder msoSendToBack
End With

With mySld.Shapes("backH")
.ZOrder msoSendToBack
End With

With mySld.Shapes("foreO")
.ZOrder msoBringToFront
End With

With mySld.Shapes("backO")
.ZOrder msoBringForward
End With

state = "O"


End If

End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *