我認爲這應該做的伎倆。它基本上使用範圍變量來處理選擇。然後它使用所選單元格的值填充數組。 CSV是可變的,包含您的結果。
請注意,selectedCells
是一個變量,在這裏不是Excel中的一些特殊功能。
[這段代碼在Excel 2002中的工作 - 不確定其他版本]
Dim selectedCells As Range
Dim rng As Range
Dim i As Integer
Dim values() As String
Dim CSV As String
' you may need some error handling here in case your selection
' isn't a range
Set selectedCells = Selection
ReDim values(selectedCells.Count - 1)
i = 0
For Each rng In selectedCells
' you may want some error handling here when populating the array
values(i) = CStr(rng.Value)
i = i + 1
Next rng
CSV = Join(values, ",")
提示:這是明智的聲明'我是Long'在更高版本的Excel;) – 2012-04-08 08:09:48