3

When I switched to MacOS Mojave, I was no longer able to save an Excel document as a PDF to a specific location using a macro.

I have had to save it to /Library/Group Containers/UBF8T346G9.Office/⁩ and then move it to the Desktop by calling a script stored in /Library/Application Scripts/com.microsoft.Excel/.

This has worked for months. Someone who uses this macro/script combo has all of a sudden been unable to do so. No other user has a problem, some having the same combination of Excel and MacOS (16.29 and 10.14.6 respectively).

When she tries to run the macro, it throws

Invalid procedure call or argument (Error 5)

specifically on the line that calls this script.

There is another script at the beginning of the macro that does not take an argument and is working. I used MsgBox to see what string was being passed to AppleScriptTask, plugged it into the script using Script Editor, and ran it without issue.

Here is the AppleScript:

 ExistsFile(sPath)

 on ExistsFile(sPath)

      set sPath to sPath as POSIX file
      tell application "Finder" to set sPath to file sPath
      set dest to (path to desktop)
      move sPath to dest without replacing

 end ExistsFile

Here is the call from the macro:

 result = AppleScriptTask("moveToDesktop.scpt", "ExistsFile", sPath & strJobNumber & " Cover Page.pdf")

I tried the following based on what I have seen on other forums:

  • Set the filename to a variable and passing that to AppleScriptTask
  • Removing the extension in the script, removing the extension in the folder, and combinations of those two
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • https://www.rondebruin.nl/mac/applescripttask.htm provides vba-code to copy script to location (be aware, you have to copy it once manually!)- You did reboot after copy script? – ComputerVersteher Dec 22 '19 at 06:52
  • Maybe path is wrong, see https://stackoverflow.com/a/46697372/9439330. There`/Users/username/Library/Application Scripts/com.microsoft.Excel`is the path. – ComputerVersteher Dec 22 '19 at 06:58
  • Remove the first line of script ([implicit run handler](https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_about_handlers.html#//apple_ref/doc/uid/TP40000983-CH206-SW15), that runs' ExistsFile without sPath Argument ) . And give it a proper name (e.g. CopyFileToDesktop ). If that doesn't help, use an [Error-Hanfler](https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_error_xmpls.html#//apple_ref/doc/uid/TP40000983-CH221-SW1). – ComputerVersteher Dec 22 '19 at 11:02

3 Answers3

2

In MacOS Mojave and newer, you'll need to do the following:

Open System Preferences - Security and Privacy - Privacy Tab - Automation - Excel ~ check off Finder.

Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
1

Sounds like it could be a permissions error if it fails to run for one user only. This page has all the requirements to run the AppleScriptTask command. Possible solution could be to enable the correct permissions for the script to run using chmod command from terminal. This will provide permission for root and current user. If this doesn't work, double check that all the requirements are met on the user's system.

cd <path to script file>
sudo chmod 755 moveToDesktop.scpt
Matts
  • 1,301
  • 11
  • 30
1

Its the spaces in the parameters you are passing to the AppleScript. You have at least one one before "Cover Letter.pdf" (and then one between "Cover" and "Letter"), probably in other cells as well that you are using to create the parameter. I had the same problem as well as it was driving me mad that the AppleScript itself was working fine when feeding it the combined parameter directly.

fredlcore
  • 33
  • 1
  • 7