印刷設定(ヘッダーに画像を指定)LeftHeaderPicture, CenterHeaderPicture, RightHeaderPicture
ヘッダーに画像を表示するには
- LeftHeaderPicture プロパティ、CenterHeaderPicture プロパティ、RightHeaderPicture プロパティ を使用して、Graphic オブジェクト を取得します。
- Graphic オブジェクト で、表示する画像ファイルを取得(Filename プロパティ)します。また、その他、画像ファイルのさまざまな設定を行います。(詳細は、印刷設定(ヘッダー・フッターに画像を設定)Graphic オブジェクト を参照してください。)
- 実際に画像を表示するには、LeftHeader プロパティ、CenterHeader プロパティ、RightHeader プロパティ などに、VBA コードの「&G」を設定します。(VBA コード に関しては、印刷設定(ヘッダー/フッター)書式コード・VBAコード を参照してください。)
PageSetup.LeftHeaderPicture プロパティ
PageSetup.LeftHeaderPicture プロパティを使用して、左ヘッダーに画像を表示するための設定を行います。実際に画像を表示するには、PageSetup.LeftHeader プロパティ に、VBA コード「&G」を指定します。
object.PageSetup.LeftHeaderPicture
引数・戻り値
- object ・・・ 対象となる Worksheet オブジェクト を指定します。
- LeftHeaderPicture プロパティで、Graphic オブジェクトを取得し、画像の設定を行います。
(例)画像(C:\Sample.bmp)を左ヘッダーに表示する設定
With Activesheet.PageSetup
LeftHeaderPicture.Filename = “C:\Sample.bmp”
LeftHeader = “&G”
End With
PageSetup.CenterHeaderPicture プロパティ
PageSetup.CenterHeaderPicture プロパティを使用して、ヘッダー中央に画像を表示するための設定を行います。実際に画像を表示するには、PageSetup.CenterHeader プロパティ に、VBA コード「&G」を指定します。
object.PageSetup.CenterHeaderPicture
引数・戻り値
- object ・・・ 対象となる Worksheet オブジェクト を指定します。
- CenterHeaderPicture プロパティで、Graphic オブジェクトを取得し、画像の設定を行います。
(例)画像(C:\Sample.bmp)をヘッダー中央に表示する設定
With Activesheet.PageSetup
CenterHeaderPicture.Filename = “C:\Sample.bmp”
CenterHeader = “&G”
End With
PageSetup.RightHeaderPicture プロパティ
PageSetup.RightHeaderPicture プロパティを使用して、右ヘッダーに画像を表示するための設定を行います。実際に画像を表示するには、PageSetup.RightHeader プロパティ に、VBA コード「&G」を指定します。
object.PageSetup.RightHeaderPicture
引数・戻り値
- object ・・・ 対象となる Worksheet オブジェクト を指定します。
- RightHeaderPicture プロパティで、Graphic オブジェクトを取得し、画像の設定を行います。
(例)画像(C:\Sample.bmp)を右ヘッダーに表示する設定
With Activesheet.PageSetup
RightHeaderPicture.Filename = “C:\Sample.bmp”
RightHeader = “&G”
End With
ヘッダーに画像を設定する
サンプルVBAソース
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
Sub Sample_HeaderFooter03() Dim w As Worksheet Dim pict As String Set w = ActiveSheet pict = CreateObject("WScript.Shell").SpecialFolders("MyDocuments") & "/sample01.jpg" 'プリンタとの通信を遮断(印刷設定を高速化) Application.PrintCommunication = False With w.PageSetup '表示する画像のパス&名前 .CenterHeaderPicture.Filename = pict '画像の比率を維持 '※元画像との比率が異なる場合は Height の値が基準となる .CenterHeaderPicture.LockAspectRatio = msoTrue '元画像のサイズ 500 .CenterHeaderPicture.Width = 500 '元画像のサイズ 300 .CenterHeaderPicture.Height = 150 '画像の色(自動) .CenterHeaderPicture.ColorType = msoPictureAutomatic '画像の明度( 50% ) .CenterHeaderPicture.Brightness = 0.5 '画像のコントラスト( 50% ) .CenterHeaderPicture.Contrast = 0.5 'トリミングの範囲を設定 .CenterHeaderPicture.CropTop = 0 .CenterHeaderPicture.CropBottom = 250 .CenterHeaderPicture.CropLeft = 0 .CenterHeaderPicture.CropRight = 210 'ヘッダー中央に画像を表示 .CenterHeader = "&G" End With 'プリンタとの通信を再開 Application.PrintCommunication = True 'プレビュー表示 w.PrintPreview End Sub |
実行結果
サンプルVBAソース 実行結果
設定画面を表示
[ページ設定] – [ヘッダー/フッター] タブ を選択し[ヘッダーの編集]
「中央部」にカーソルを移動して、[図の書式設定] をクリック
ヘッダーに表示した画像の原画
関連記事
-
-
ワークシートにクリップボードの内容を貼り付ける(Paste メソッド)
Paste メソッド 指定したワークシート上にクリップボードのデータを貼り付けま …
-
-
印刷設定を高速化(PrintCommunication プロパティ)
PrintCommunication プロパティ PrintCommunicat …
-
-
印刷の用紙サイズを設定(PageSetup.PaperSize プロパティ)
PageSetup.PaperSize プロパティ PageSetup.Pape …
-
-
印刷設定(ヘッダー・フッターに画像を設定)Graphic オブジェクト
Graphic オブジェクト Graphic オブジェクト は、ヘッダーおよびフ …
-
-
最近使用したファイル(RecentFile オブジェクト,RecentFiles コレクション)
最近使用したファイル(RecentFile オブジェクト,RecentFiles …
-
-
ユーザー設定のビュー(CustomView オブジェクト)
ユーザー設定のビュー CustomView オブジェクトは、登録されている各ビュ …
-
-
白黒印刷(PageSetup.BlackAndWhite プロパティ)
PageSetup.BlackAndWhite プロパティ PageSetup. …
-
-
印刷設定(ページごとに異なるヘッダー・フッターを設定)Page オブジェクト・HeaderFooter オブジェクト
Page オブジェクト ページごとに異なるヘッダーおよびフッターを設定する場合、 …
-
-
ブックのコピーを保存(SaveCopyAs メソッド)
SaveCopyAs メソッド SaveCopyAs メソッド は、現在開いてい …
-
-
ウィンドウの状態を取得・設定(WindowState プロパティ)
ウィンドウの状態を取得・設定(WindowState プロパティ) Window …