How to run a Macro in MS Publisher from DOS command prompt?

J

joe1977

Publisher 2003 with XP Prof.
I am trying to run my macro as mspub.exe "document.pub" /mMyMacro
where "MyMacro" is my macro but instead of running it, it's just MS
Publisher opening "document.pub" file.
How can I make it open the macro (this is for automate purposes).

btw: my macro security setting are set to "low".

Thanks
 
E

Ed Bennett

Publisher 2003 with XP Prof.
I am trying to run my macro as mspub.exe "document.pub" /mMyMacro
where "MyMacro" is my macro but instead of running it, it's just MS
Publisher opening "document.pub" file.
How can I make it open the macro (this is for automate purposes).

I don't believe you can. You could instead (I think) write a VBScript
that calls Publisher as a COM server and run the macro that way (well,
recode the macro in VBScript).
 
J

joe1977

thanks for your post! I tryied doing that! But it also does not work
(COM says: Unknown function Run()".

I tryied different combinations:

$pub->Documents[1]->RunMacro(MyMacro);
$pub->Documents[1]->Run(MyMacro);
$pub->Documents[1]->Application->Run(MyMacro);

please notice I need to run it through PHP :(


Thanks for your reply.
 
E

Ed Bennett

thanks for your post! I tryied doing that! But it also does not work
(COM says: Unknown function Run()".

I tryied different combinations:

$pub->Documents[1]->RunMacro(MyMacro);
$pub->Documents[1]->Run(MyMacro);
$pub->Documents[1]->Application->Run(MyMacro);

please notice I need to run it through PHP :(

Publisher doesn't expose embedded macros to the COM interface, as far as
I know. You'd have to take the macro and rewrite it in PHP through the
Publisher COM server. (I have precisely zero experience with PHP, so am
unable to help you there.)
 
J

joe1977

but how would you run a Publisher macro from any COM?



thanks for your post! I tryied doing that! But it also does not work
(COM says: Unknown function Run()".
I tryied different combinations:
$pub->Documents[1]->RunMacro(MyMacro);
$pub->Documents[1]->Run(MyMacro);
$pub->Documents[1]->Application->Run(MyMacro);

please notice I need to run it through PHP :(Publisher doesn't expose embedded macros to the COM interface, as far as
I know. You'd have to take the macro and rewrite it in PHP through the
Publisher COM server. (I have precisely zero experience with PHP, so am
unable to help you there.)
 
E

Ed Bennett

but how would you run a Publisher macro from any COM?

Well, if I were using VB6's COM interface, I'd do something like

Sub DoSomethingWithPublisher()
Dim pApp As New Publisher.Application
Dim pDoc As Publisher.Document
Set pDoc = pApp.Open(fileName)

Dim tB As Publisher.Shape
Set tB = pDoc.Pages(n).Shapes.AddTextBox(144, 144, 144, 144)
tB.TextFrame.TextRange.Text = "Foo"
pDoc.Save

pDoc.Close
pApp.Exit
End Sub

This is equivalent to opening the document fileName and running the
following macro within the publication:

Sub Macro()
Dim tB as Shape
Set tB = ThisDocument.Pages(n).Shapes.AddTextBox(144, 144, 144, 144)
tB.TextFrame.TextRange.Text = "Foo"
pDoc.Save
End Sub

....then killing the Publisher instance.
 
J

joe1977

well, that ok, but my main question was ... how you going to run your
"Macro()" from COM interface??
 
E

Ed Bennett

well, that ok, but my main question was ... how you going to run your
"Macro()" from COM interface??

Like I've said 3 times, I'm not going to, as you can't (to the very best
of my knowledge).

I am going to port Macro() to the language of my choice, and execute it
through the COM interface.
 

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