assigning same function to the actions of every picture in a photo album

K

kaston3

I have a ppt photo album show - each slide consists of a single
picture.

I know how to assign a function to the mouse click for every picture
using the ppt interface but I need to do it through VBA code so as not
to have to go over all the pictures one by one.

What Visual Basic array/collection contains the pictures in a show or
slide and how do I refer to them in VBA?

I want to use a for...next loop and action>function assignment in the
loop.

Thanks
 
S

Steve Rindsberg

Kaston3 said:
I have a ppt photo album show - each slide consists of a single
picture.

I know how to assign a function to the mouse click for every picture
using the ppt interface but I need to do it through VBA code so as not
to have to go over all the pictures one by one.

What Visual Basic array/collection contains the pictures in a show or
slide and how do I refer to them in VBA?

What action do you want to assign?
 
K

kaston3

for each picture mouse click->assign macro

I know how to do it picture by picture ->just rightclicking on picture
and choosing action configuration>mouse click>macro, here a pulldown
list of available functions/macros appear.

I also know the Visual BASIC algorithm and where to put (alt+f11)

What I need is a way to refer to a particular picture in a slide.

for example the following is used to refer to the current pesentation
like ActivePresentation.SlideShowWindow:


1. How can I refer to
a) slide 1, 2, 3 and so on
b) A picture loaded into each slide at design time

2. How can I assign a macro to a mouseclick on each picture:
(the names inside the for..next loop are made up. That's what I need
to know: their actual name in Visual basic for Applications.

for x= 1 to ActivePresentation.Slides.Count
slide(n).picture(1).action.mouseclick=mymacro()
next
 
S

Steve Rindsberg

See below:

Kaston3 said:
for each picture mouse click->assign macro

I know how to do it picture by picture ->just rightclicking on picture
and choosing action configuration>mouse click>macro, here a pulldown
list of available functions/macros appear.

I also know the Visual BASIC algorithm and where to put (alt+f11)

What I need is a way to refer to a particular picture in a slide.

for example the following is used to refer to the current pesentation
like ActivePresentation.SlideShowWindow:

1. How can I refer to
a) slide 1, 2, 3 and so on
b) A picture loaded into each slide at design time

2. How can I assign a macro to a mouseclick on each picture:
(the names inside the for..next loop are made up. That's what I need
to know: their actual name in Visual basic for Applications.

for x= 1 to ActivePresentation.Slides.Count
slide(n).picture(1).action.mouseclick=mymacro()
next

This should get you cranking:

Sub DoSomethingToAllThePictures()

Dim oSh As Shape
Dim oSl As Slide

' Loop through all the slides in the presentation
For Each oSl In ActivePresentation.Slides

' Loop through all the shapes on each slide
For Each oSh In oSl.Shapes
' decide what to do with the shape
Select Case oSh.Type

Case Is = msoPicture, msoLinkedPicture
' do the deed:
With oSh.ActionSettings(ppMouseClick)
.Run = "NameOfYourMacroHere"
' Stuff the macro recorder picks up
' You may or may not want to use it
'.SoundEffect.Type = ppSoundNone
'.AnimateAction = msoFalse
End With

Case Else
' ignore it
End Select

Next oSh
Next ' Slide

End Sub
 
K

kaston3

Thanks for that code, It doesn't seem to work, though. The mouse action
does not get assigned to the pictures at run time.

I assigned your DoSomethingToAllThePictures() procedure to a mouse
click action for a picture in the first slide. That is, the picture
assignment at run time should occur to all pictures from number 2 to
number of slides. I also want to randomize the show order of those
slides and that works ok with another routine triggered in the first
slide mouseclick but the call to your code does not work.

I even tried diferent ways to call the sub like

..Run = thesub (with no quotes) or thesub().
 
S

Steve Rindsberg

Kaston3 said:
Thanks for that code, It doesn't seem to work, though. The mouse action
does not get assigned to the pictures at run time.

I assigned your DoSomethingToAllThePictures() procedure to a mouse
click action for a picture in the first slide. That is, the picture
assignment at run time should occur to all pictures from number 2 to
number of slides. I also want to randomize the show order of those
slides and that works ok with another routine triggered in the first
slide mouseclick but the call to your code does not work.

Don't assign the code I posted to an action; instead run it manually once to
assign actions to your pictures. You have to fill in the name of the macro you
really want the click action to run. Type that in place of "YourMacroNameHere"
or whatever it was I included in the original code
 
K

kaston3

Yes. Running the macro that assigns the actions just one at design time
makes more sense. However I did it that way and only the picture of the
first slide gets assigned the sub. There has to be some problem in the
loop that stops it at the first slide.

I tried using different sub and funtions and the code works BUT only
for slide 1.

(I think the old for...next loop is easier to understand and wonder how
to do it using for... next instead of for each...next)

Thanks
 
S

Steve Rindsberg

Kaston3 said:
Yes. Running the macro that assigns the actions just one at design time
makes more sense. However I did it that way and only the picture of the
first slide gets assigned the sub. There has to be some problem in the
loop that stops it at the first slide.

I tried using different sub and funtions and the code works BUT only
for slide 1.

Let's define what you mean by "works but only for slide 1"

If you run it then go to slide XX and look at the mouseclick action setting for
the picture there, what is it?

I get the macro I've specified assigned to each picture. If you have an ole
embedded thingie or something else that's not strictly speaking a picture, the
macro will ignore it; you'd need to modify it a little.

If the macro you assigned to the picture doesn't work except on slide one, you
need to change your macro.
(I think the old for...next loop is easier to understand and wonder how
to do it using for... next instead of for each...next)

For X = 1 to ActivePresentation.Slides.Count
' do stuff like
ActivePresentation.Slides(X).Name = "Slide Number: " & cstr(X)
Next X

It's workable but more tedious to write, and in theory slower.
 
K

kaston3

"Works for slide one" means that the action gets assigned to the
picture of the slide as intended but only the first slide (Obviously I
check the actions in the other pictures/slides and there is no action
assigned to them).

I just did some testing -- creating a mini presentation with three
pictures-- and it seems that the problem is that all slides/pictures
except slide one were created using the photo album feature in
powerpoint 2003.

So it looks like there no difference since I get the same options when
I click on them but there has to be some difference in the way the
pictures are treated as powerpoint objects when loaded with photo
album.


When in your code there's:
Case Is = msoPicture, msoLinkedPicture

the pictures loaded using photo album are not recognized as msoPicture
type or msoLinkedPicture --

So, what kind of object can they be??
 
K

kaston3

OK, that was the problem. Pictures loaded using the photo album feature
are loaded as autoshapes -- I only needeed to change that in your code



msoAutoShape instead of msoPicture

Now everything works. The photoalbum and your code have saved me lots
of time since I have to do this with many other collections of
pictures.

Thanks for your time!
 
D

David M. Marcovitz

I'm glad you got it to work. Just beware that msoAutoShape is a broad
category, so you might end up with lots of stuff containing links to
macros if you have a lot of non-picture autoshapes.
--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.loyola.edu/education/PowerfulPowerPoint/
 
S

Steve Rindsberg

Kaston3 said:
OK, that was the problem. Pictures loaded using the photo album feature
are loaded as autoshapes -- I only needeed to change that in your code

msoAutoShape instead of msoPicture

I wouldn't do that unless you're VERY sure that there won't be any other shapes
on the slide. All of the rectangles and other drawn stuff will also get
assigned an action setting this way. If that's ok then ... um ... it's ok.

I'd still use the code I posted in reply to your earlier message though.
Now everything works. The photoalbum and your code have saved me lots
of time since I have to do this with many other collections of
pictures.

Thanks for your time!

Glad to hear it ... you're quite welcome. It's been fun.
 
S

Steve Rindsberg

I just did some testing -- creating a mini presentation with three
pictures-- and it seems that the problem is that all slides/pictures
except slide one were created using the photo album feature in
powerpoint 2003.

Aha. That's the problem. PhotoAlbum inserts rectangles and gives them a
picture fill set to each picture you choose to insert.

Change the case selector part of the code like so and it should behave better:

Select Case oSh.Type

Case Is = msoPicture, msoLinkedPicture
' do the deed:
With oSh.ActionSettings(ppMouseClick)
.Run = "NameOfYourMacroHere"
' Stuff the macro recorder picks up
' You may or may not want to use it
'.SoundEffect.Type = ppSoundNone
'.AnimateAction = msoFalse
End With

Case is = msoAutoShape ' ie a rectangle
If oSh.Fill.Type = 6 then ' Picture Filled
' repeat the action settings commands from above
End If
Case Else
' ignore it
End Select
 

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