In VBA how can I start a newly created media shape when created

J

John Crawford

I am playing with VBA in PP just to see whether I can make things
happen.
I am trying to create a multimedia shape to play a song, and what I
want to do is start it as soon as it is created.
The following code creates it, and when I look at the values they
are all what I expected.
==============================
With ActivePresentation.Slides(1).Shapes _
.AddMediaObject(FileName:="e:\MS Office Data\PowerPoint Data\The
Celts Enya.wav", _
Left:=ActivePresentation.Slides(1).Shapes(3).Left, _
Top:=ActivePresentation.Slides(1).Shapes(3).Top, _
Width:=10, Height:=10)
.ZOrder (msoSendToBack)
With .AnimationSettings
With .PlaySettings
.PlayOnEntry = True
.LoopUntilStopped = msoCTrue
.StopAfterSlides = 1
.PauseAnimation = msoFalse
End With
.AdvanceMode = ppAdvanceOnTime
.AdvanceTime = 0
.Animate = msoCTrue
End With
End With
=============================
However whan I run the code that creates it I want it to start
playing immediately. However the shape is created ok, but I must click
to get it to start. If, however I have the created shape, and start the
show again (with the creation disabled so I do not get a second
instance) it does start right away.
Is there any way that I can get it to do as I need?
Thanks in advance
John Crawford
 
A

Austin Myers

Joan, an interesting situation. The PlayOnEntry is where it's throwing you.
The problem is, there is no entry, you are creating the object. When PPT
"plays" a slide, it does so from a (for lack of a better term) script that
describes everything on the slide and it's timing. By creating the media
object after the start of the slide, there is no PlayOnEntry to process.

Not certain why you would approach the solution in this way other than as an
experiment, but you may be able to use the, ActionVerb = "Play" function. I
haven't used it myself but after reading the VBA help file it looks like it
should do the trick.


Austin Myers
MS PowerPoint MVP Team

Provider of PFCMedia http://www.pfcmedia.com
 
J

John Crawford

Austin:
It is primarily an experiment and a learning tool, to see what I can
do and how. I had an idea that it would not work as coded, because it is
not knowd whan the slide starts.
I looked at the "Play" action verb, but did not experiment with it.
I will.
There is a semi-practical use for this. I have a 'pre' presentation
slide. It is the first slide of a presentation, and I want it to be able
to do any or all of the following:
- display random shapes, in random colours, in different places
- display random pictures as the slide background
- diaplay random pictures in different places
- play a song

All or any of these are triggered by clicking an object. This starts
everything going. Since the Command$ function is not available in VBA, I
read a file to set the parameters for the process. Since the
pictures/shapes are created when this process starts, I thought that the
multi-media shape would be created like the others.
If I cannot get it to work dynamically, I can just create it on the
slide and then stop it if needed (or I can use a second click, but that
is not as clean)
The reason for thsi type of pre-slide, is just to give the audience
something to look at before the show begins. By reading a file in, it
would be easy to tailor the presentation to the topic, audience.
John Crawford
 
A

Austin Myers

Steve Rindsberg said:
What if the code tossed in a .View.GoToSlide(x) immediately after creating
the
shape on slide X?

Hmmm, don't know Steve but my thought is you would have to go to the
preceeding slide in order to reset the animations. (Or reset them in code.)
 
J

John Crawford

Austin & Steve:
Using the GotoSlide does seem to work as you suggested. It does
start the music playing. However because the slide is reset the
remaining stuff does not function (the random shapes etc.). It is one
step along the process, however, and it is perhaps where the statement
is located that is the issue.
Thanks for your help. The experiment continues...
John Crawford
 
J

John Crawford

Where there is a will there is a way. I have gotten everything to worp
'pretty' much the way I want it to run. It is a little convoluted, but
it works without breaking. There is still a little tweeking I need to do
to clean it up and give me all the flexability I need.
Thanks to you and Austin for your patience and help in persuing this
mind experiment.
John Crawford.
 

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