AppleScript从Excel工作表中获取活动单元格的值

时间:2012-04-17 03:31:44

标签: excel applescript

尝试从Excel工作表中获取当前突出显示的单元格的值

set x to null
tell application "Microsoft Excel"
    tell worksheet "Sheet1" of active workbook
       set x to value of active cell as string
       display dialog x
    end tell
end tell

AppleScript上方将x设置为“缺失值”。我在这里做错了什么,有没有其他方法来获得活跃细胞的价值?

我正在使用Microsoft Excel 2011 for MAC version 14.0.0

1 个答案:

答案 0 :(得分:1)

如果查看excel的applescript字典,您会看到“active cell”是应用程序的属性。它不是工作表或工作簿的属性。所以这有用......

tell application "Microsoft Excel"
    set x to value of active cell as string
    display dialog x
end tell

它也是一个窗口的属性,所以这也有效......

tell application "Microsoft Excel"
    tell window 1
        set x to value of active cell as string
        display dialog x
    end tell
end tell