Using Select Case with Visible property

C

CompleteNewb

Hi all.

I'm making a painting demo type thing with Powerpoint, and wanted to be able
to change a shape or image (which indicates the side of the house) depending
on which of several other shapes (swatches) is clicked. For instance, I
have 1 shape which looks like bricks (Rectangle 1), one that looks like
vinyl siding (Rectangle 2), etc. The side of the house would be Rectangle 5
(or Image 5, or whatever, if it' s an imported jpg).

So, when I click Rectangle 1, I'd like my image of a brick wall to appear
where Rectangle 5 is. If I click Rectangle 2, I'd like the brick wall image
to become the image of a vinyl sided wall. I will be using imported jpg's
as the images.

My thinking was that I'd use a Select Case to cycle through and see which
jpg object is currently visible, then make that one invisible and make the
appropriate jpg visible. However, I don't know the most efficient way to do
this (ie. would I just make all the wall images invisible and the one I want
seen visible? Or is it better to cycle through the visible property?).

Can someone supply me with a code snippet for Powerpoint that they think
would be the best way to approach this? I used to use VBA a lot, but this
Powerpoint vba seems to be a lot different (for example, I'm not used to
seeing this mso stuff; has the vba prefix been replaced with mso for the vba
editors in Office?)

I'm using Office 2003 on Windows XP Home.

Thanks for any help, it's appreciated.
 
S

Steve Rindsberg

Hi all.

I'm making a painting demo type thing with Powerpoint, and wanted to be able
to change a shape or image (which indicates the side of the house) depending
on which of several other shapes (swatches) is clicked. For instance, I
have 1 shape which looks like bricks (Rectangle 1), one that looks like
vinyl siding (Rectangle 2), etc. The side of the house would be Rectangle 5
(or Image 5, or whatever, if it' s an imported jpg).

So, when I click Rectangle 1, I'd like my image of a brick wall to appear
where Rectangle 5 is. If I click Rectangle 2, I'd like the brick wall image
to become the image of a vinyl sided wall. I will be using imported jpg's
as the images.

My thinking was that I'd use a Select Case to cycle through and see which
jpg object is currently visible, then make that one invisible and make the
appropriate jpg visible. However, I don't know the most efficient way to do
this (ie. would I just make all the wall images invisible and the one I want
seen visible? Or is it better to cycle through the visible property?).

Can someone supply me with a code snippet for Powerpoint that they think
would be the best way to approach this?

If it were mine to do, I think I'd use tags.

*** WARNING ***
AIR CODE
*** WARNING ***

For example, select Rectangle 1 and run this to give it a tag named
"ColorSwatch" whose value is "Brick"

Sub TagSwatch()
With ActiveWindow.Selection.ShapeRange(1)
Call .Tags.Add("Color","Brick")
End With
End Sub

Then use similar code to tag each of the shapes that should be made
visible/invisible with the appropriate tag like so:

Sub TagTarget()
' note, this lets you select and tag multiple shapes
With ActiveWindow.Selection.ShapeRange
Call .Tags.Add("Target","Brick")
End With
End Sub

Now add this macro to the presentation and set it as a Run Macro action for
each of your swatch shapes:

Sub SwatchClick(ClickedShape As Shape)
Dim oSl as Slide
Dim oSh as Shape
For Each oSh in ClickedShape.Parent.Shapes
' is it a "target" shape?
If Len(oSh.Tags("Target")) > 0 Then
If oSh.Tags("Target") = ClickedShape.Tags("Color") Then
oSh.Visible = True
Else
osh.Visible = False
End If
End If
Next
End Sub
 

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