Header
PowerPoint tips, hints and tutorials that will change your presentations for ever!

INDEX

 

Jigsaws
Sounds
Video
Custom Shows
vba code
NaviSlides
Games for teachers
Bullets
Triggers
Security
Flash Cards
Multiple Instances
PowerPoint 2007
Mail Merge
Random events
Animation
Hyperlinks
Set spellcheck language


Home buttonTutorial buttonContact buttonProducts button


Mouseover Trigger an Animation With vba Code

We are often asked if this is possible. The usual answer is "NO" - the vba object model has no inbuilt way to do this.

Here's a clever trick that can work though!

It relies on the little known fact that action buttons or shapes can be triggered from the keyboard and of course action buttons and shapes can trigger animation!

Try this out set up an animation triggered buy an action button or shape. If you don't know how to do this read "Triggers a Definitive Guide" first!

Now in show mode press TAB and then ENTER, you should see a dotted line indicating that the button is selected and then the animation run.

Even better if you do not want to see the button simply drag it off slide - it will still work! If there are more than one button you may have to press TAB multiple times to select the correct button.

To get this to work from vba you can use use the SENDKEYS command. We normally avoid this command but I think it's the only way here.

The code to press TAB then ENTER

Sub anim()
SendKeys("{TAB}")
SendKeys("{ENTER}")
End Sub

Now add a shape and give it a MOUSEOVER action of run the code above. Before testing the mouseover make sure that the animation runs OK if you manually press TAB then ENTER. If you add the mouseover shape BEFORE the action button you may find that TAB selects the mouseover shape and not the trigger action button. If this happens try selecting the action button and sending to back.

This can be used to simulate a mouseover trigger.

Download an example file here (ZIpped)

Example of rollover picture

If you have several triggers simply add more TAB SendKey lines.

For example to simulate Tab Tab Enter to click a second button:

Sub anim()
SendKeys("{TAB}")
SendKeys("{TAB}")
SendKeys("{ENTER}")
End Sub

 

Another Way (not recommended)!

This is only suitable when the slide has NO existing animations

The code needs to:

  1. Remove any animations (probably)

  2. CREATE an animation that plays as the slide opens

  3. Re_open the slide to play

Here is some typical code

Sub anim_vba()
Dim osld As Slide
Dim oshp As Shape
Dim oeff As Effect
Dim i As Integer
Set osld = SlideShowWindows(1).View.Slide 'current slide
'zap animations
For i = 1 To osld.TimeLine.MainSequence.Count
osld.TimeLine.MainSequence(i).Delete
Next i
Set oshp = osld.Shapes(3) ' alter to suit
Set oeff = osld.TimeLine.MainSequence _
.AddEffect(oshp, msoAnimEffectBox, msoAnimateLevelNone, msoAnimTriggerWithPrevious, 1)
SlideShowWindows(1).View.GotoSlide (osld.SlideIndex) ' restart slide
End Sub

This will work from a userform and you can have several buttons running different animations

 

 

 
 

Back to the Index Page

POWERPOINT BLOG

Articles on your favourite sport

Free Microsoft PowerPoint Advice, help and tutorials, Template Links
This website is sponsored by Technology Trish Ltd
© Technology Trish 2007
Registered in England and Wales No.5780175
PowerPoint® is a registered trademark of the Microsoft Corporation