使用AppleScript在Excel 2016中打开文件

3
在Excel 2016中,以下AppleScript代码:
tell application "Microsoft Excel"
    activate
    open "Macintosh HD:Users:path:to:file"
end tell

打开一个对话框,要求用户授权screenshot 在之前的Excel版本中,文件会立即打开。 似乎微软现在不允许在没有明确用户权限的情况下从脚本中打开文件。
有没有办法绕过这个对话框?

3个回答

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

这在High Sierra上无法工作。有什么建议吗? - MacDeveloper

0

这将打开所选文件

tell application "Finder"
    open selection with MicrosoftExcel
end tell

MacOS 10.14 Mojave | Excel for Mac 16.20

MacOS 10.14 Mojave | Excel for Mac 16.20


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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接