また、VBAでの[For Each セル範囲]が簡単には出来ませんので、セル範囲を単一セルオブジェクトの
配列に分解する関数も作りました。
単一セル(A1)・セル範囲(A1:B5)・セル範囲コンテナ(A1:B5;D3:F10)を意識せずに使えます。
『Cells.Count & [ For Each セル範囲 ] 』 ( Ver 1.4 , 2009/9/2 )
http://blog.livedoor.jp/addinbox/archives/51243120.html
コード: 全て選択
~~ 利用例 ~~
(7/24 分解セルを順にセレクトするコードを追加)
(7/25 ThisComponent以外のテストケースを追加)
Sub Main
Dim oDoc As Object
Dim oCells As Object
Dim oCellsItem() As Object
Dim oController As Object
Dim lngCount As Long
Dim i As Long
Dim strMsg As String
Dim strSheetName As String
oDoc = ThisComponent
'oDoc = GetComponent("無題 1",True) '(注)
oCells = oDoc.getCurrentSelection
'oCells = oDoc.Sheets(1).getCellRangeByName("A5:C8")
MsgBox GetCellsCount(oCells)
lngCount = GetCellsItem(oCells, oCellsItem)
strMsg = Join(Split(oCells.AbsoluteName,"$"),"") & chr(13) & "CellsCount=" & lngCount
For i = 1 to lngCount
strMsg = strMsg & chr(13) & Join(Split(oCellsItem(i).AbsoluteName,"$"),"")
Next i
MsgBox strMsg
oController = oDoc.getCurrentController()
With oCellsItem(1)
strSheetName = .Spreadsheet.Name
oController.setActiveSheet(.Spreadsheet)
End With
For i = 1 to lngCount
MsgBox "Next Cell select"
With oCellsItem(i)
If (strSheetName <> .Spreadsheet.Name) Then
strSheetName = .Spreadsheet.Name
oController.setActiveSheet(.Spreadsheet)
End If
End With
oController.select(oCellsItem(i))
Next i
End Sub
http://blog.livedoor.jp/addinbox/archives/51192547.html
AddinBox/VBAユーザーの為のOpenOffice.org 備忘録 『ユーザー定義関数の一覧』
http://blog.livedoor.jp/addinbox/archives/51249421.html