Him
Him

Reputation: 103

call a powerpoint macro with arguments from batch

I want to call a powerpoint macro from my batch file like this

"c:\program files\microsoft office\office14\POWERPNT.exe" /M x5_template.pptm macro_name(argument)

Problem is that it's working fine without argument but my requirement is to pass the argument. Any words on it how to pass the argument?

Upvotes: 1

Views: 4857

Answers (2)

Steve Rindsberg
Steve Rindsberg

Reputation: 3528

Another approach: Write an EXE that accepts your parameters on the command line. The EXE then invokes PowerPoint and calls the macro and passes any necessary parms. Here's a VB snippet that might help:

Dim oPPTapp As Object
Set oPPTapp = New PowerPoint.Application

' make it visible if need be
oPPTapp.Visible = True  

If Err.Number <> 0 Then
    oPPTapp.Quit
    Set oPPTapp = Nothing
    Exit Sub
End If

' Call PPT VBA subroutine using Parameter, which you've
' parsed from the command line
oPPTapp.Run "NameOfSubRoutine", Parameter

You could make it even more generic if you use the first command line parm as the name of the macro to run and then pass any further parm(s) as parameter(s)

Upvotes: 1

PA.
PA.

Reputation: 29339

AFAIK you can't.

But, I use the following strategy to solve some very simple cases. It might be insuficient for your needs, as it requires planning in advance all of the possible parameters.

Suppose I have a macro ChangeAllFont(newfont as String) that takes one String parameter.

I declare several utility macros that invoke the macro with some of the desired parameters. For example,

Sub ChangeAllFontArial()
 Call ChangeAllFont("Arial")
End Sub

and,

Sub ChangeAllFontTimes()
 Call ChangeAllFont("Times New Roman")
End Sub

And then I might later on invoke the powerpoint either as

POWERPNT /M template.ppt ChangeAllFontArial

or

POWERPNT /M template.ppt ChangeAllFontTimes

Upvotes: 0

Related Questions