calling a macro in PPT from vbscript

M

mstuehler

All,

I'm working on a vbscript (that will run using windows script host), to
automate the modification of an existing Powerpoint presentation

The presentation contains a macro (named "someMacro") - I'd like to be able
to run that macro from vbscript. I've tried this:

Dim oApp
Set oApp = CreateObject("Powerpoint.Application")
oApp.Visible = True
Dim oPres
Set oPres = oApp.Presentations.Open("pres.ppt")
oApp.Run "someMacro"

The macro definitely exists, but when I run this script, I get this error:

Application.Run : Invalid request. Sub or function not defined
Code: 80048240

Any advice or suggestions would be greatly appreciated!

Cheers,
Matt Stuehler
 
M

mstuehler

All,

After a bit of testing, I discovered the following:

Using this code:

Set oApp = CreateObject("Powerpoint.Application")
Set oPres = oApp.Presentations.Open("pres.ppt")
oApp.Run "SomeMacro"

I get an error - Powerpoint complains that the macro is undefined

However, if I do this:

Set oApp = CreateObject("Powerpoint.Application")
Set oPres = oApp.Presentations.Open("pres.ppt")
Set oSlide = oPres.Slides(1).Duplicate
oApp.Run "SomeMacro"

Then it works!!!

It's as though Powerpoint doesn't recognize the existence of the macro until
I execute the "oPres.Slides(1).Duplicate" method

I don't know what other methods have this same effect, but is there a
rational explanation for this?

Many thanks in advance for your advice and insight!

Cheers,
Matt Stuehler
 

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