Applescript to Open MS Word and execute a Macro

D

Douglas McKibbin

I am having trouble opening MS Word (2004) and executing an existing
macro using Applescript. If I place the VB code in ""s the script will
not compile as ...

Tell Application "Microsoft Word"
do visual basic "my VB code goes in here ......."
end tell

or

Tell Application "Microsoft Word"
do visual basic "Execute(MyMacro)"
end tell

I get an error message like Can't continue <<event MSWDdovb>>.

How can I execute this macro from Applescript?
Thanks
Douglas McKibbin
 
P

Paul Berkowitz

I am having trouble opening MS Word (2004) and executing an existing
macro using Applescript. If I place the VB code in ""s the script will
not compile as ...

Tell Application "Microsoft Word"
do visual basic "my VB code goes in here ......."
end tell

or

Tell Application "Microsoft Word"
do visual basic "Execute(MyMacro)"
end tell

I get an error message like Can't continue <<event MSWDdovb>>.

How can I execute this macro from Applescript?
Thanks

First you need to open the document that contains the macro, unless it's in
your Normal template or a Startup Template, and then, for most cases (all
except Normal template), use Application.Run if you use 'do Visual Basic:

tell application "Microsoft Word"
do Visual Basic "Documents(\"Other Document.doc\").Activate
Application.Run \"MyProcedure\""
end tell

for a macro in an open document. For full details, see this webpage:

<http://www.word.mvps.org/MacWordNew/WordAppleScript.htm>

Refresh it a few times if you are in safari, to see it. Read the "Calling
Installed Macros" section part way down.

If you are in Word 2004, you do not need 'do Visual Basic'; you can use the
command

run VB macro "MyProcedure"

but use the same rules for the name of the macro. If it's in the Normal
template or a Startup template, the name is enough. Otherwise you have to
open and activate the document that contains the macro and include the
document's entire file path.
--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 

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