How to access CommandButton properties in different slides

  • Thread starter Thread starter thomas.schoenfelder
  • Start date Start date
T

thomas.schoenfelder

I'm working on a Quiz Game with PP2003.

The following code changes the picture of a CommandButton (cuurent
slide only) when clicking on it

""
Private Sub CommandButton1_Click()

CommandButton1.Picture = LoadPicture("D:\MyPicture.jpg")

End Sub
""

Along with this click I want to change pictures of all other
CommandButtons on other slides.


I tried something like this:
ActivePresentation.Slides(4).CommandButton1.Picture =
LoadPicture("D:\MyPicture.jpg")

but it wont' work.


??? How do I accesss properties of all other CommandButtons I have in
other slides ???
 
Instead of ActivePresenations.Slides(4), you want Slide4 as in:

Slide4.CommandButton1.Picture = LoadPicture("D:\MyPicture.jpg")

You also want to be careful about specifying an absolute path for the
picture. When you move/distribute the presentation, MyPicture.jpg isn't
necessarily going to be on the D drive.

--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/

(e-mail address removed) wrote in @g44g2000cwa.googlegroups.com:
 
Dave,

Thanks for the quick reply

"Slide4.CommandButton1.Picture = LoadPicture("D:\MyPicture.jpg")"
returns an error "Object missing"


Do I have to define a Public Sub instead of a Private Sub to get global
access to all CommandButtons ?
 
No, you do not need a public sub because the object itself is, in some
ways, public. You must have an existing CommandButton1 on slide 4 for
this to work. Are you sure there is a something called CommandButton1 on
slide 4? This exact code worked for me (except I did it on Slide1 and
used a different picture).
--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/

(e-mail address removed) wrote in @g43g2000cwa.googlegroups.com:
 
Dave,
Thanks a lot, you saved my day

Now it works :-))))

Now to be flexible on the number of slides I want to use a Variable
(SL_Name) instead of Slide1 ... Slide9

something like this...
"
Sub Cancel_Joker()


NrSlides = ActivePresentation.Slides.Count
For i = 1 To NrSlides
SL_Name = ActivePresentation.Slides(i).Name
SL_Name.Button_5050_1.Picture = LoadPicture("MyPic.jpg")

Next i

End Sub
"
How do I need to define/use this variable (SL_Name) to make this code
work



regards

Thomas
 
I was afraid you were going to ask that. I don't know the answer.
Hopefully, one of the more advanced VBA experts will chime in with an
answer.
--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/

(e-mail address removed) wrote in @g44g2000cwa.googlegroups.com:
 
How about this:

Dim oSl as Slide

For Each oSl in ActivePresentation.Slides
With oSl.Shapes("CommandButton1")
.OLEFormat.Object.Picture = LoadPicture("c:\pix\yourpicture.jpg")
End With
Next

If you can get an object reference to the shape that represents the control
(button, textbox, whatever) then tack on .OLEFormat.Object and carry on as
though you're setting properties in the control's property sheet or click event
handler.
 
Steve,

thanx a lot, your fix works great.
that's exactly what I was after.

best regards

Thomas
 
Back
Top