How to access CommandButton properties in different slides

  • Thread starter thomas.schoenfelder
  • 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 ???
 
D

David M. Marcovitz

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:
 
T

thomas.schoenfelder

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 ?
 
D

David M. Marcovitz

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:
 
T

thomas.schoenfelder

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
 
D

David M. Marcovitz

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:
 
T

thomas.schoenfelder

Steve,

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

best regards

Thomas
 

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