Object Colour change on click

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using Visual Basic, is there a script that would change the colour of an
object (or button) when it is clicked and then change it to a different
colour if clicked again? I'm designing a quiz and want to select an shape
containing an answer; for that to change colour so that we all know which one
we're talking about. and then to change colour again so that we know we've
dealt with it. Hope that makes sense.

Thanks Spence
 
Hi Spencer

You can create this effect without vba.

You need three buttons / shapes each a different colour. Stack them on top
of each other and set the top two shapes with an exit animation triggered by
a click on itself
--
 
Thanks John,

That certainly is one easier solution. However, it would be nice not to have
to do so much copying and pasting.

I was thinking of useing VB so that later on it is easier to edit the text
 
Yes, this is possible with VBA. Here is an example:

Sub FlipColor(oShp As Shape)
If oShp.Fill.ForeColor.RGB = vbBlue Then
oShp.Fill.ForeColor.RGB = vbRed
Else
oShp.Fill.ForeColor.RGB = vbBlue
End If
End Sub

Assign this macro to a shape and each time you click it, it will change
alternate between blue and red.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
That certainly is one easier solution. However, it would be nice not to have
to do so much copying and pasting.

I was thinking of useing VB so that later on it is easier to edit the text
on the objects i.e. only have to edit it once rather than three times for
each item.

This makes sense, then. So long as you understand that a VBA solution won't work in
the free Viewer, but it doesn't sound as though that's an issue in your situation.

So, add this macro and assign it to each shape whose color you want to "flip" as an
action setting. Set the color of the shape to whatever color you've defined as the
default color.

We could probably take it a step beyond and teach it to work with any clicked shape
and remember the shape's original color, then set it back on re-click if need be.

Sub FlipColors(oSh as Shape)

Dim lDefaultColor as Long
Dim lHighlightColor as Long

' Edit these as needed
lDefaultColor = RGB(0,0,255) ' pure blue
lHightlightColor = RGB(255,255,0) ' yellow

With oSh.Fill.ForeColor

Select Case .RGB
Case lDefaultColor
.RGB = lHighlightColor

Case lHighlightColor
.RGB = lDefaultColor
End Select

End With

End Sub

End Sub
 
Round two:

Highlight shapes in PowerPoint
http://www.rdpslides.com/pptfaq/FAQ00798.htm

This one remembers the original shape's color and sets it back to that (which also
means that you don't have to set the shape to any particular color to make it work
in the first place).

And because PPT won't let you assign macros to multiple selected shapes at a time,
there's this:

Assign an Action Setting, Run Macro action to multiple shapes at once
http://www.rdpslides.com/pptfaq/FAQ00799.htm
 
Hi I am new to this and was searching for this solution. And I see I am only 13 years late to the game here. I used the code from David M.

Sub FlipColor(oShp As Shape)
If oShp.Fill.ForeColor.RGB = vbBlue Then
oShp.Fill.ForeColor.RGB = vbRed
Else
oShp.Fill.ForeColor.RGB = vbBlue
End If
End Sub

It works great and I was able to substitute other colors...but I would like to have a 4 color changing option. I have tried multiple edits to this code but I am stuck...can someone help me?
 
Back
Top