Michele Percich Michele Percich - 3 months ago 25
AppleScript Question

Open file in Excel 2016 using AppleScript

In Excel 2016, the following AppleScript:

tell application "Microsoft Excel"
activate
open "Macintosh HD:Users:path:to:file"
end tell


opens a dialog asking the user to grant access screenshot
With previous Excel's versions, the file opened immediately.
It seems that Microsoft doesn't allow any more to open a file from a script without the express user permission.

Is there a way to bypass the dialog?

Answer

Use a file object or an alias object instead of a string

tell application "Microsoft Excel"
    activate
    open file "Macintosh HD:Users:path:to:file"
    -- or --> open alias "Macintosh HD:Users:path:to:file"
end tell

When you have a POSIX path, you can use this (open POSIX file "..." doesn't work)

tell application "Microsoft Excel"
    activate
    set my_file to POSIX file "/Users/name/path/to/file"
    open my_file
end tell
Comments