2012-10-05 87 views
1

在VBA我可以做在Excel中,通过选定单元格是这样的循环:如何使用Applescript在Excel中循环选定的单元格?

for each c in Selection 
    ' do things 
next 

我试图做的AppleScript相同的,但我似乎并没有取得任何进展。我得到当前单元格,但即使当我做

set c to count of selection 

的结果是,C设置为0

的Excel中的AppleScript手册似乎并没有帮助,也没有谷歌搜索。

感谢

回答

3

事实证明,你有使用“count large”来获取选择中的单元格数量。一旦你到达那里,这是简单的 - 这样的:

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 

,然后再通过属性列表中,直到我发现了一个有一个。这是一个很好的方式来到物业名单。也许AppleScript编辑器有更快的方式,但我是一个命令行人员。

+0

注意:如果您选择几个单元格,则略过一点,然后选择更多的单元格(我在同一列中试过时),这不起作用。 –

0

你可以尝试这样的事情:

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 

你可以阅读更多here

你还可以尝试:

set cellCount to count of (cells of selection) 
+0

其实问题是在选择中的细胞 - 没有选择细胞(这是很好的文件)。不过,非常感谢您的回答。 – simone

+0

我太快读到你的问题了。我以为你在问如何“在Excel中循环单元格”。 – adayzdone

+0

哎呀你说得对 - 坏头衔。对不起,再次感谢。 – simone

相关问题