- Home ›
- Excel VBA入門 ›
- セルの罫線の設定 ›
- HERE
罫線の色の設定
広告
罫線の色についてはBorderオブジェクトの「ColorIndex」プロパティで設定します。ここで「ColorIndex」プロパティは文字色の設定で使った「ColorIndex」プロパティと同じで全部で57種類の色が用意されており、0から56のインデックス番号で指定します。(詳しくは『文字色の設定』を参照して下さい)。
記述の方法は次のようになります。
Dim border1 As Border Set border1 = Range("A1").Borders(xlEdgeTop) border1.ColorIndex = 12
サンプルプログラム
では簡単なサンプルで試してみましょう。
Sub テスト() With Range("B2:C3") .Borders(xlEdgeTop).LineStyle = xlContinuous .Borders(xlEdgeTop).ColorIndex = 12 .Borders(xlEdgeBottom).LineStyle = xlContinuous .Borders(xlEdgeBottom).ColorIndex = 32 .Borders(xlEdgeLeft).LineStyle = xlContinuous .Borders(xlEdgeLeft).ColorIndex = 6 .Borders(xlEdgeRight).LineStyle = xlContinuous .Borders(xlEdgeRight).ColorIndex = 45 End With End Sub
上記マクロを実行すると次のようになります。
( Written by Tatsuo Ikura )