如何使用Applescript在Excel中循环选定的单元格?

在VBA中,我可以做这样的事情,在Excel中循环选定的单元格:

for each c in Selection ' do things next 

我正在尝试在AppleScript中做同样的事情,但我似乎没有得到任何地方。 我确实得到了当前的单元格,但是即使是当我这样做

 set c to count of selection 

结果是c被设置为0。

Excel的苹果手册似乎没有帮助,也没有谷歌search。

谢谢

事实certificate,你必须使用“计数大”来获得select单元格的数量。 一旦你到达那里,就很简单 – 就像这样:

 tell application "Microsoft Excel" repeat with j from 1 to count large of selection -- do stuff with the cell set value of cell j of selection to "cell_" & j end repeat end tell 

为了到达那里,我不得不这样做

 tell application "Microsoft Excel" set c to properties of selection end tell return c 

然后通过属性列表,直到我find一个有希望的。 这是一个很好的方式来到物业名单。 也许在AppleScript编辑器有一个更快的方法,但我是一个命令行的人。

你可以尝试这样的事情:

 tell application "Microsoft Excel" set range1 to range "A1:A5" set value of range1 to {{1.0}, {2.0}, {3.0}, {4.0}, {5.0}} set range2 to range "B1:B5" set value of range2 to {3} repeat with i from 1 to 5 set formula of row i of column 3 to "=A" & i & "+B" & i end repeat end tell 

你可以在这里阅读更多

你也可以尝试:

 set cellCount to count of (cells of selection)