0
votes

On a slide of a powerpoint presentation, I added an action button (checkbox) that is clickable when I make a presentation. So I have the possibility to write a function that is as follows:

Private Sub case_choix1_Click()

Dim OSh As Shape
  For Each OShp In Shapes
    If OShp.Name = "answer_mask" Then
        If (case_choix1.Value) Then
            OShp.Visible = False
            OShp.Flip msoFlipHorizontal
            OShp.Flip msoFlipHorizontal         
        Else
            OShp.Visible = True
            OShp.Flip msoFlipHorizontal
            OShp.Flip msoFlipHorizontal
        End If
    End If
  Next OShp
End Sub

This function allows me to hide or see shapes that I call "answer_mask" depending on the state of my button. This function works very well with powerpoint 2010 that I used before and the execution was quick enough for me.

I now use powerpoint 2016, and this function easily takes 6-7 seconds to execute !! Even if I have less than 10 shapes and texts in total in my slide, I have this problem both when I create a new slide show or when I use my old presentations executed with powerpoint 2016.

In parallel to that, I have a more general macro that allows me to put the state of my button in a desired state. The algorithm is very similar. I'm just browsing through all my slides, find checkbox button, change de state and put "answer_mask" shapes to its default state. The time to do that is very fast.

I tried to remove all visible actions, and form manipulations. The algorithm is very fast. As soon as I add just the visible shape modification, it becomes very slow and the same for the Flip

I wonder why this part of the program takes a long time on this version of powerpoint and if you see things that need to be changed to improve its execution.

Thanks for your suggestions.

2

2 Answers

0
votes

[Posted as an answer rather than a comment because you really wouldn't want to have to sift through code posted as comments.]

If for some reason the slowdown is due to cycling through many shapes, you could try this:

Private Sub case_choix1_Click()

'Dim OSh As Shape
' Should be this
Dim OShp As Shape

  On Error Resume Next
  Set OShp = Shapes("answer_mask")
  If Err.Number = 0 then
        If (case_choix1.Value) Then
            OShp.Visible = False
            OShp.Flip msoFlipHorizontal
            OShp.Flip msoFlipHorizontal         
        Else
            OShp.Visible = True
            OShp.Flip msoFlipHorizontal
            OShp.Flip msoFlipHorizontal
        End If
   Else
      Exit Sub    
  End If

End Sub
0
votes

As I have a number of "answer_mask" from 1 to near 10 depending on the slide I have, this code is quicker than my previous one.

Private Sub case_choix1_Click()

Dim OShp As Shape

  On Error Resume Next
  Set OShp = Shapes("answer_mask")
  If Err.Number = 0 Then
         For Each OShp In Shapes
           If OShp.Name = "answer_mask" Then
            If (case_choix1.Value) Then
                OShp.Visible = False
                OShp.Flip msoFlipHorizontal
                OShp.Flip msoFlipHorizontal
            Else
                OShp.Visible = True
                OShp.Flip msoFlipHorizontal
                OShp.Flip msoFlipHorizontal

            End If    
        End If
          Next OShp      
   Else
      Exit Sub
  End If

End Sub