VBA: Slow execution working with shape visibility

K

Kevin Dufendach

Using VBA to change properties (visibility, text, transparency) of a shape on
a slide with many others runs slowly.

I have a slide with a shape set to run the following code (below) which
toggles the visibility of another shape and toggles a document tag.
Everything works as expected, but the update takes about 0.5 seconds (on a
Centrino Duo 1.66 GHz).

I believe the slow execution has to do with the number of other shapes on
the slide (about 70). If I create a new first slide and copy the over to it,
it runs almost instantaneously. If I then add several shapes to that new
slide, it again runs slowly. I've tried referencing the object directly
(.Slides(1).Shapes(56).Fill.Visible = msoTrue), but that doesn't seem to
change anything. Does anyone know if there is a better way for me to be
referencing shapes or changing properties to speed things up?

Thanks so much!
Kevin

'''''''''''''''''''''''''
Sub ToggleShow1()

On Error GoTo OnError

With ActivePresentation
Select Case .Tags("Show1")
Case "False"
.Tags.Add "Show1", "True"
.Slides(1).Shapes("Check1").Fill.Visible = msoTrue
Case Else
.Tags.Add "Show1", "False"
.Slides(1).Shapes("Check1").Fill.Visible = msoFalse
End Select
End With

NoErrors:
Exit Sub

OnError:
End Sub
''''''''''''''''''''''''''''''
 
J

John Wilson

Hi Kevin

I'm not sure this would run much faster but could you not do away with the
tegs and use this to toggle

With ActivePresentation.Slides(1).Shapes("Check1")
..Fill.Visible = Not .Fill.Visible
End With
--
-------------------------------------------
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk
email john AT technologytrish.co.uk
 
K

Kevin Dufendach

I get the same slow result with the ".fill.visible =
not .fill.visible" command. I wonder if I could use animation appear/
disappear to change this. Unfortunately, I don't know how to use VBA
to trigger an animation item, and I still need to use VBA since I need
to change the tag (I reference it in a different macro later. This is
a toggle box for options for a different macro).
 
A

Austin Myers

Kevin,

You might try naming the shapes instead of using a number. When you use the
number the code has to count (enumerate) each shape on the slide (to make
certain there are 56 of them (or whatever number your after.) I've found
executing code on a named shape is almost instant.



Austin Myers
Microsoft PowerPoint MVP Team

Creator of PFCPro, PFCMedia and PFCExpress
http://www.playsforcertain.com
 
K

Kevin Dufendach

I'll bet your suspicion is correct, that PPT is taking time to redraw
the slide. Unfortuantely, the hardware acceleration option didn't
help anything. I think the best option would be to step away from the
".Fill.Visible" property and use an "appear" animation, as that works
just fine even with many objects on the same slide. I was thinking I
could set the figure to appear with click on a trigger and also to
disappear with a trigger, and then I could use VBA to activate the
Appear or Disappear effect based on what the "Check1" tag value is.
Using "activepresentation.SlideShowWindow.View.Next," I can advance
the next animation in the main timeline, but unfortunately, I can't
figure out how to advance an interactive sequence. Do you have any
idea how to advance an interactive sequence using VBA?
 
K

Kevin Dufendach

Thanks for the suggestion, David. Shyam always has great stuff, and
this tutorial is no exception. Unfortunately, it doesn't yet answer
my question as to how to advance an InteractiveSequence animation
(page still under construction).
 
S

Shyam Pillai

Kevin,
Firing a trigger sequence by code isn't supported natively. You could send a
mouse-click message to the shape under the current cursor position but it's
too klunky for a general solution.

Is this code running in slide show mode or design mode?

Regards,
Shyam Pillai

Image Importer Wizard
http://skp.mvps.org/iiw.htm
 
K

Kevin Dufendach

Thanks Shyam,

I'm sorry to hear that you can't control trigger sequences (at least,
not easily). I'm running this in slide show mode. Basically, this is
a checkbox that sets an option that the rest of the presentation will
reference. e.g.:

-----------------------------------------------------------
| |
| |
| Whales |
| by Kevin Dufendach |
| |
| |
| [X] go to random [ Go! ] |
-----------------------------------------------------------

When the user checks the "Go to random" checkbox, then every time
[ Go! ] is pressed, a random slide is brought up. When it's not
checked, then the [ Go! ] button just goes to the next slide (the
[ Go! ] button is part of the master, so it's repeated on every
slide). The program should also remember what the state of the
checkbox is so that the next time the presentation is run, it will
remember the user's preference and have that automatically set.

Thanks, all, for your suggestions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top