Run Office:2011 VBA macro from AppleScript (on OS X Yosemite)

Jamie Garroch
Jamie Garroch used Ask the Experts™
on
I have seen several methods for running macros from AppleScript on the web but none seem to work. This is the one that looks closest to being relevant for Office:mac 2011:

tell application "Microsoft PowerPoint"
activate
run VB macro "myMacroName"
end tell

Open in new window


But no matter what I put after run VB macro, the script editor keeps throwing this error:

Syntax Error
Expected end of line, etc. but found identifier.


So I opened the relevant dictionary in the script editor to check that the method exists using File / Open Dictionary, selecting the relevant Microsoft Office:mac application and searching for run VB macro I found this:

AppleScript-run-VB-macro.png
This looks like the macro name and optional parameters are supposed to be on separate lines but that throws the same error.

If it's possible to run a macro and this issue is resolved, where can the macro reside? Only in an open document or can it be called within an installed VBA application add-in too?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Try
tell application "Microsoft PowerPoint"
activate
tell active workbook
run VB macro "myMacroName"
end tell
or:

tell application "Microsoft PowerPoint"
activate
run VB macro macro name "myMacroName"
end tell
Jamie GarrochSenior Technical Consultant at BrightCarbon
Commented:
run VB macro macro name "myMacroName" is definitely part of the answer but it was still creating an error.

I think I found the other part.

This doesn't work:
tell application "Microsoft PowerPoint"

Open in new window

And in fact, for some bizarre reason it's autocorrecting it to this:
tell application "Microsoft PowerPoint x64"

Open in new window

Which is the Windows version of PowerPoint 2013 running in Parallels!

So, that lead me to think more explicitly:
tell application "Macintosh HD:Applications:Microsoft Office 2011:Microsoft PowerPoint"

Open in new window

But that didn't work either.

However, by simply adding .app to the end, this does!
tell application "Macintosh HD:Applications:Microsoft Office 2011:Microsoft PowerPoint.app"

Open in new window

Even better, it's allowing me to call publicly declared macros in a loaded PPAM add-in :-)

I am left wondering why the simple "Microsoft PowerPoint" doesn't work and if my solution is safely deployable to multiple machines.
Jamie GarrochSenior Technical Consultant at BrightCarbon

Author

Commented:
The solution required two changes to the original code, one from user strung and one from myself after more reading/prototyping/testing

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial