Reputation: 1892
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
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?
Upvotes: 3
Views: 5312
Reputation: 1
I use this scriptlet to work around the access permissions dialog:
'with timeout of 10 seconds
try
-- File open may time out due to Apple's sandbox security rules.
open FileName
on error
-- A Cancel and Grant Access dialog pops up and stops execution. Click the Grant Access button.
tell application "System Events" to tell process "Microsoft Excel" to tell button "Grant Access" of window "Open" of application process "Microsoft Excel" of application "System Events" to perform action "AXPress"
end try
end timeout'
Excel version: 16.32, Mac OS version: 10.14.6
Upvotes: 0
Reputation: 1
This opens the selected files
tell application "Finder"
open selection with MicrosoftExcel
end tell
MacOS 10.14 Mojave | Excel for Mac 16.20
Upvotes: 0
Reputation: 7191
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
Upvotes: 5