選択範囲の行数と列数
選択範囲の行数と列数を確認するマクロを作成しました。
Sub ma0020_Selection_EndRow_EndColumn Dim maCurrentS as Object maCurrentS = ThisComponent.CurrentSelection With maCurrentS.RangeAddress MsgBox _ " シート番号 = " + .Sheet + _ " シート名 = " + ThisComponent.Sheets(maCurrentS.RangeAddress.Sheet).Name + chr(13) + _ " StartRow = " + .StartRow + " StartColumn = " + .StartColumn + chr(13) + _ " EndRow = " + .EndRow + " EndColumn = " + .EndColumn + chr(13) + chr(13) + _ " 行数 = " + maCurrentS.Rows.Count + " 列数 = " + maCurrentS.Columns.Count _ ,64, "選択範囲の行数と列数" End With End Sub |
マクロの機能(添字は0から始ります)
選択範囲のシート番号、選択範囲のシート名
選択範囲の左上行番号、左端列番号、右下行番号、右端列番号
選択範囲の行数、列数 の表示
マクロの説明
ThisComponent.Sheets(maCurrentS.RangeAddress.Sheet).Name を
ThisComponent.Sheets(.Sheet).Name に変更すると
OOo1.0.3, OOo1.1.0, OOo1.1.1, OOo2.0, StarSuite8 では、Basicシンタックスエラーが発生しました。
OOo1.1.2, OOo1.1.3, OOo1.1.4, OOo1.1.5, StarSuite7 では、正常でした。
ThisComponent.CurrentSelection を
ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("A21:C25") に変更すれば、
マクロの実行結果は、選択範囲が、 "A21:C25" に修正されます。
Excelでは、次のようになります。
Sub X0020_Selection_EndRow_EndColumn()
Dim maLastRow As Long
Dim maLastColumn As Long
With Selection
maLastRow = .Row + .Rows.Count - 1
maLastColumn = .Column + .Columns.Count - 1
MsgBox _
" シート番号 = " & ThisWorkbook.ActiveSheet.Index & _
" シート名 = " & ThisWorkbook.ActiveSheet.Name & Chr(13) & _
" StartRow = " & .Row & " StartColumn = " & .Column & Chr(13) & _
" EndRow = " & maLastRow & " EndColumn = " & maLastColumn & Chr(13) & Chr(13) & _
" 行数 = " & .Rows.Count & " 列数 = " & .Columns.Count _
, 64, "選択範囲の行数と列数"
End With
End Sub
OO1.1.2, 1.1.3, 1.1.4, 1.1.5, StarSuite7 用サンプルマクロ(Calc)
OOo1.0.3, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5 2.0, StarSuite7, 8 用サンプルマクロ(Calc)
「ファイルのダウンロード」について 一旦ファイルを保存して
「ma0020_selection_endrow_endcolumn.zip」を「ma0020_selection_endrow_endcolumn.sxc」に
「ma0020_selection_endrow_endcolumn2.zip」を「ma0020_selection_endrow_endcolumn2.sxc」に変更後、実行して下さい。
2006年11月03日(金) 10:53:17 Modified by zizidai_3373