SSブログ

数式が設定されているセルに背景色を設定するマクロの実験 LibreOffice Calc Basic [LibreOffice Calc Basic]

数式が設定されているセルに背景色を設定するマクロの実験

FormulaBGcolor1.png

 

Sub formulaBGColor()
'アクティブシートの数式の有るセルにバックグラウンドカラーを設定する実験
'

Dim oRange As Object
Dim oCursor As Object
Dim usedRow As Long
Dim usedColumn As Long
Dim x As Long
Dim y As Long


'アクティブシートの使用済み範囲を調べる-------------------------------------------
    'スタート位置 A1  A1を変えると結果も変わる
        oRange = ThisComponent.CurrentController.Activesheet.getCellRangeByName("A1")
    'カーソル設定
        oCursor = ThisComponent.CurrentController.Activesheet.createCursorByRange(oRange)
        oCursor.gotoEndOfUsedArea(True)
    ' objCursor.collapseToCurrentRegion()
    'UsedRang 最終行、列
        usedRow=oCursor.Rows.Count
        usedColumn=oCursor.Columns.Count
    'MsgBoxに表示
        'Msgbox "最終行  " & usedRow & chr(10) & "最終列  " & usedColumn,,"ActiveSheet UsedRange"
       
'UsedRangeから1セルづつ、数式せるか調べて数式セルなら背景色を設定する------------------------
    For y=0 To usedRow-1        '行数
        For x=0 To usedColumn-1    '列数
            'NG
            'If ThisComponent.CurrentController.Activesheet.getCellByPosition(x,y).getType()=FORMULA Then _
            'ThisComponent.CurrentController.Activesheet.getCellByPosition(x,y).CellBackColor =RGB(255,0,0)
       
        Select Case ThisComponent.CurrentController.Activesheet.getCellByPosition(x,y).getType()
                case com.sun.star.table.CellContentType.EMPTY
                    '    oCell( i ) = "空白です。"
                case com.sun.star.table.CellContentType.VALUE
                    'oCell( i ) = oSheet.getCellByPosition(0, i ).Value
                case com.sun.star.table.CellContentType.TEXT
                    'oCell( i ) = oSheet.getCellByPosition(0, i ).String
                case com.sun.star.table.CellContentType.FORMULA
                    ThisComponent.CurrentController.Activesheet.getCellByPosition(x,y).CellBackColor =RGB(255,0,0)
                case Else
                    'oCell( i ) = "不正な型のDataです。"
            End Select
           
        Next x
    Next y

End Sub

 

追記 数式セルカの判定変更
If
ThisComponent.CurrentController.Activesheet.getCellByPosition(x,y).getType()=_

com.sun.star.table.CellContentType.FORMULA
Then _
            ThisComponent.CurrentController.Activesheet.getCellByPosition(x,y).CellBackColor =RGB(255,250,0)

Sub formulaBGColor2()
'アクティブシートの数式の有るセルにバックグラウンドカラーを設定する実験
'

Dim oRange As Object
Dim oCursor As Object
Dim usedRow As Long
Dim usedColumn As Long
Dim x As Long
Dim y As Long


'アクティブシートの使用済み範囲を調べる-------------------------------------------
    'スタート位置 A1  A1を変えると結果も変わる
        oRange = ThisComponent.CurrentController.Activesheet.getCellRangeByName("A1")
    'カーソル設定
        oCursor = ThisComponent.CurrentController.Activesheet.createCursorByRange(oRange)
        oCursor.gotoEndOfUsedArea(True)
    ' objCursor.collapseToCurrentRegion()
    'UsedRang 最終行、列
        usedRow=oCursor.Rows.Count
        usedColumn=oCursor.Columns.Count
    'MsgBoxに表示
        'Msgbox "最終行  " & usedRow & chr(10) & "最終列  " & usedColumn,,"ActiveSheet UsedRange"
       
'UsedRangeから1セルづつ、数式せるか調べて数式セルなら背景色を設定する------------------------
    For y=0 To usedRow-1        '行数
        For x=0 To usedColumn-1    '列数
            '
            If ThisComponent.CurrentController.Activesheet.getCellByPosition(x,y).getType()=_

com.sun.star.table.CellContentType.FORMULA Then _
            ThisComponent.CurrentController.Activesheet.getCellByPosition(x,y).CellBackColor =RGB(255,250,0)
               
        Next x
    Next y

End Sub

 

 


nice!(0)  コメント(1)  トラックバック(0) 
共通テーマ:パソコン・インターネット

nice! 0

コメント 1

SWADWAY

Buy Flagyl In Burbank https://bbuycialisss.com/ - Buy Cialis cialis modo de uso <a href=https://bbuycialisss.com/#>cheapest cialis 20mg</a> Comprar Cialis En Gijon
by SWADWAY (2020-07-04 17:27) 

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0


Linuxランキング

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。