在Excel 2016中,以下AppleScript:
tell application "Microsoft Excel"
activate
open "Macintosh HD:Users:path:to:file"
end tell
打开一个对话框,要求用户授予访问权限
使用以前的Excel版本,文件立即打开。
似乎微软不允许在没有明确用户许可的情况下从脚本中打开文件。
有没有办法绕过对话框?
答案 0 :(得分:5)
使用文件对象或别名对象而不是字符串
tell application "Microsoft Excel"
activate
open file "Macintosh HD:Users:path:to:file"
-- or --> open alias "Macintosh HD:Users:path:to:file"
end tell
如果您有POSIX路径,则可以使用此路径(open POSIX file "..."
不起作用)
tell application "Microsoft Excel"
activate
set my_file to POSIX file "/Users/name/path/to/file"
open my_file
end tell
答案 1 :(得分:0)
这将打开所选文件
tell application "Finder"
open selection with MicrosoftExcel
end tell
MacOS 10.14 Mojave | Excel for Mac 16.20
答案 2 :(得分:0)
我使用此脚本来解决访问权限对话框:
'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版本:16.32,Mac OS版本:10.14.6