attaching applescript to Excel buttons

I’m using Excel 2004 (that has VBA support) and am trying to run an Applescript from a button. I think the only way you can do this is by running it within VBA and attaching the VBA macro to the button. I’m trying the following code but it doesn’t work:

Sub test()
MacScript (“Macintosh HD:Users:lloydsturdy:Desktop:testscript.scpt”)
End Sub

Anyone know where I’m going wrong (or if it’s possible at all)?

It’s quite possible.
The argument of the VBA function MacScript is a string that is an apple script.


MacScript("run script  ""Macintosh HD:Users:lloydsturdy:Desktop:testscript.scpt"" )

(Hmm, the space between “script” and the double quote is both unobvious (on my screen) and important)

Unfortunatly, I know VBA better than AppleScript. The script in the above MacScript argument was faulty.
But this one works.

Sub test()
Dim scriptToRun As String

scriptToRun = "set myScript to ""Macintosh HD:Users:merickson:Desktop:tester.scpt"" as alias"
scriptToRun = scriptToRun & vbCr & "run script myScript"

MacScript (scriptToRun)

End Sub[/code]

Many thanks but when I run your script - copied exactly apart from changing the path to my desktop file - I get a “Run-time error ‘5’ - Invalid procedure call or argument” error your last line:

MacScript (scriptToRun)

I don’t know VB at all so I feel a bit blind. If it works on your computer I can only presume it’s something to do with how I’m running the code or something. I have a friend I’m seeing in a couple of days who knows a bit about VB and I’ll show him my problem and hopefully together we can spot where I’m going wrong. If I get to the bottom of it I’ll let you know.

Thanks again


When debugging what I wrote, I got that error until the as alias was added.

You’ll also get that error if the AppleScript in the file errors.

Similarly, if the AppleScript calls a user interface (e.g. display dialog) and the user presses Cancel, the VB will error, unless the AppleScript detects and handles the pressing of Cancel.

I hate to admit it but the problem turned out to be typo - your script worked perfectly!

Many thanks.