Log in

View Full Version : PowerPoint VBA - Animation Help



nsalyani
05-15-2011, 09:53 PM
Hi to All,

First time user of this Forum, Hopefully I can get some help on this.

THE REQUIREMENT:
I have a PowerPoint page with 4 squares (from autoshapes). Each square has some text in it which I have set to appear one after the other in each of the boxes upon mouse click using custom animation tools.

Once the text appears, I have an Action Setting on each box for a MACRO to run on each of the boxes upon click of the box. The Macro (in VBA seen below) is expected to change the color of the box to orange first. If the box selected is the correct one, the color of that box changes to green. If the box selected is incorrect, the color of the correct box should turn green.

THE ISSUE:
The Problem I am facing is that since I am bringing in the text into the boxes VIA custom Animation, when the Macro runs on the box, the color changes correctly, but the text in all the boxes disappears.
If however, I do not use custom Animation to bring in the text, everything works as it is suppposed to. But my requirements is to being in the text into the boxes one by one.

SAMPLE CODE FOR THE COLOR CHANGE:

Sub SelectAnswer1(shpA As Shape)
Dim shp2 As Shape
Dim ss As Slide

shpA.Fill.ForeColor.RGB = RGB(255, 165, 0)
For Each ss In ActivePresentation.Slides
For Each shpA In ss.Shapes
If shpA.HasTextFrame Then
If StrComp(shpA.TextFrame.TextRange, "Text1", vbTextCompare) = 0 Then
shpA.Fill.ForeColor.RGB = RGB(124, 242, 0)
For Each shp2 In ss.Shapes
If shp2.Fill.ForeColor.RGB = RGB(255, 165, 0) Then
y = Timer + 0.1
Do While Timer < y
DoEvents
Loop
End
End If
Next shp2
End If
End If
Next shpA
Next ss
End Sub

Any help will be greatly appreciated.

Thanks

John Wilson
05-15-2011, 11:33 PM
It works here. What version of PPT is this? Is there a reason why you loop through all the slides instead of the shapes on the currect slide?

Changing shapes with vba often resets the animation sequence and I guess this is what is happening. Not easy to fix! Maybe have the animations on one slide and then auto move to a duplicat with no animations?

John Wilson
05-16-2011, 12:37 AM
Also you may be able to do this without vba using triggers?

nsalyani
05-16-2011, 10:18 AM
I am using PPT 2003.

The reason why I am checking all slides is because I intend to have more code where I do string comparisons for blocks on other slides. Rather than having a seperate macro for each slide, I'd rather have one macro and check in all slides for the different strings of text that I am looking for.

Now coming back to your answer, you mention that it works for you?

Would you mind explaining to me how you go about setting your autoshapes and your strings in the shapes. May be I am missing a step here.

John Wilson
05-16-2011, 01:21 PM
I was using 2010, in 2003 I'm pretty sure the code would reset the animations back and lose the text.

There is no need to check all slides though to avoid just using one code module simply set ss to SlideShowWindows(1).View.Slide and it will reference the current slide.

You can download a code free solution here (http://www.pptalchemy.co.uk/Downloads/color.ppt) otherwise I would look at the duplicate slide method which is slides 2 & 3

Never going to be perfect in all versions though.

nsalyani
05-16-2011, 03:32 PM
I will try the same out on 2010. Other than that, thanks for the NO CODE reference.

Really appreciate your help.