2011-09-03 71 views
1

打开Excel 2011可有人请解释什么是错在下面的AppleScript:苹果脚本无法在Mac

tell the application id "com.microsoft.Excel" 
set excel to open workbook workbook file name "Users:Tom:Desktop:ID_Creation.xlsx" 
end tell 

我安装了Office2011。 它提供了以下错误:

/usr/bin/osascript test.scpt 
test.scpt:59:137: execution error: Microsoft Excel got an error: Can’t continue open workbook. (-1708) 

我甚至尝试推出并激活命令,但徒劳无功。

回答

2

Ahhh我看到您的问题:您没有指定驱动器名称。所以,相反,你应该做的

set excel to "<your_drive_name>:Users:Tom:Desktop:ID_Creation.xlsx" 
+0

谢谢。这工作。但没有驱动器名称这是在Office2008工作。这两个版本是否有区别? – Subrat

+0

@Subrat我认为在Office2008中,驱动器名称是自动提供的。 – fireshadow52

0

你不需要用磁盘和长路径的工作,如果你的文件是在桌面上或在某个主文件夹。有内置的快捷方式告诉你各种重要文件夹的路径。例如,“桌面文件夹的路径”,“主文件夹的路径”,“文档文件夹的路径”,“下载文件夹的路径”。它们都作为您的文件夹的别名系统,包括自动指定启动磁盘的正确名称,以便即使稍后更改它,脚本仍然可以工作。如果您希望将桌面文件夹的路径替换为文本而不是别名 - 例如,构建文件路径 - 则只需询问“文本文件夹的路径”。

我不使用Excel ,但这里是使用搜索的例子:

tell application "Finder" 
    set theFilePath to (the path to desktop folder as text) & "ID_Creation.xlsx" 
    open file theFilePath 
end tell 

...这应该工作在Excel中打开该文件在您的计算机上,假定Excel是与该文件扩展名打开文件的默认应用程序。

这是你的脚本改写使用这种技术,它应该在你的计算机上工作,假设你的脚本的其余部分是正确的 - 正如我所说,我不使用Excel,所以我不能测试这个:

tell the application id "com.microsoft.Excel" 
    set theFilePath to (the path to desktop folder as text) & "ID_Creation.xlsx" 
    set excel to open workbook workbook file name theFilePath 
end tell 

...这是你的脚本清理了一下,为解决Excel中以常规方式,并使用一个变量为您打开工作簿是不完全一样的Excel的名字,因为这可以被混淆稍后再说。

tell application "Excel" 
    set theFilePath to (the path to desktop folder as text) & "ID_Creation.xlsx" 
    set theExcelWorkbook to open workbook workbook file name theFilePath 
end tell