BoldとItalicの設定

広告

次はスタイルの設定です。太字(Bold)と斜体(Italic)の設定です。太字を設定するにはFontオブジェクトの「Bold」プロパティで、斜体を設定するにはFontオブジェクトの「Italic」プロパティを使います。

Dim font1 As Font

Set font1 = Range("A1").Font
font1.Bold = True
font1.Italic = True

Fontオブジェクトを別途取り出さずに、次のようにまとめて記述しても構いません。

Range("A1").Font.Bold = True
Range("A1").Font.Italic = True

「Bold」プロパティと「Italic」プロパティは排他的なプロパティではありませんので、同時にTrueを設定する事も可能です。

サンプルプログラム

では簡単なサンプルで試してみましょう。

testcellfont2.bas

Sub テスト()
    
    Range("A2:B3").Value = "ABC"

    Range("A3").Font.Bold = True
    Range("B2").Font.Italic = True
    Range("B3").Font.Bold = True
    Range("B3").Font.Italic = True

End Sub

上記マクロを実行すると次のようになります。

BoldとItalicの設定

( Written by Tatsuo Ikura )