Search code examples
excelvbamacosms-wordapplescript

Problem communicating with 3rd party apps via VBA on Mac M1


I have created a VBA add-in for Microsoft Word. Both a Windows and Mac version. The add-in communicates with 3rd party apps. This has worked fine for years. I'm now struggling making this work for the Mac-version with M1-based macs (Maybe also Big Sur related). The communication works partly via a dylib written i c, via stdin and stdout. Secondly some functions use AppleScriptTask.
I can't make either of these two methods work.

AppleScriptTask always return the error:

Run-time error '5'
Invalid procedure call or argument

VBA-code: s = AppleScriptTask("WMscript.scpt","Test","")

I tried scripts with .scpt, .scptd and .applescript.
Also newly created scriptfiles with simple test.script:

on Test(paramS)
    tell application "Finder"
         activate
    end tell
end Test

The api works in other applications, but I can't open 3rd party apps in it when used from VBA.

I use these special folders for the all the 3rd party files to circumvent sandboxing for both methods:
/Library/Application support/Microsoft/Office365/User Content/Add-ins/
~/Library/Application Scripts/com.microsoft.word/
~/Library/containers/com.microsoft.word/Data/

I also tried the GrantAccessToMultipleFiles(FileArray) function. It always returns 'True' regardless which filenames are sendt in the array. It never prompt the user.

Running:
M1 Mac
Big sur 11.6 (M1)
Microsoft Word for Mac 16.54 (21101001)


Solution

  • The ApplceScriptTask problem was related to an incorrect path, for the script file: Incorrect: ~/Library/Application Scripts/com.microsoft.word/ Correct: ~/Library/Application Scripts/com.microsoft.Word/

    Had to be Uppercase W.