2012-10-05 71 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

相關問題