Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 835
Michele Percich Avatar asked Jan 21 '26 09:01

Michele Percich


1 Answers

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
like image 108
jackjr300 Avatar answered Jan 24 '26 04:01

jackjr300