6-2 印刷処理
印刷については、細かな位置合わせ等の特殊なケ−スを省き自動記録した内容をマクロへ
組み込むだけで特に問題有りません。ただし標準設定部分も全て自動記録されそのまま
貼り付けると余分な時間がかなり掛かる。本項では主に自動記録の内容を明確にして
最低限のマクロ作成の手助けになる内容を記載する。
6-2(1) 印刷処理例
下記例は毎日作成しているグラフを印刷するかダイアログで表示したケ−ス。
シ−ト表示を元に戻すマクロを入れてあり長くなっているが、印刷は
"PrintOut"の1行だけ。
sub 例151()
ms$ = "このグラフをプリントアウトしますか?"
ms1 = MsgBox(ms$, 4, "プリント確認")
If ms1 = 7 Then
Windows(bname).Activate
Sheets("実行計画").Activate
Exit Sub
End If
'dataプリント
ActiveWindow.SelectedSheets.PrintOut Copies:=2
Windows(bname).Activate
Sheets("実行計画").Select
End Sub
・上記の「Copies:=1」は印刷部数2部を指定(グラフを2箇所に掲示する為:省略時は1部)
・ブック内の全シ−ト印刷は、
"ActiveWorkbook.PrintOut" とする。
・ワ−クシ−トのペ−ジ指定は、
"ActiveWindow.SelectedSheets.PrintOut From:=2, To:=3, Copies:=1"
とする(本例は2〜3ペ−ジ)。
6-2(2) 印刷条件の各種設定
[1]印刷範囲

ActiveSheet.PageSetup.PrintArea = "$A$1:$I$22"
[2] 行・列のタイトル

With ActiveSheet.PageSetup
.PrintTitleRows = "$2:$2"
.PrintTitleColumns = ""
End With
[3] ヘッダ−の指定

With ActiveSheet.PageSetup
.LeftHeader = "15-2(3)-@"
.CenterHeader = "15-2(3)-A"
.RightHeader = "15-2(3)-B"
End With
[4] フッタ−の指定

With ActiveSheet.PageSetup
.LeftFooter = "15-2(4)−@"
.CenterFooter = "15-2(4)-A"
.RightFooter = "15-(4)−B"
End With
[5] 余白の指定
余白の大きさはをポイント(1ポイントは1/72約0.35mm)単位で指定

With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.787) '[3]
.RightMargin = Application.InchesToPoints(0.787) '[4]
.TopMargin = Application.InchesToPoints(0.984) '[1]
.BottomMargin = Application.InchesToPoints(0.984)'[2]
.HeaderMargin = Application.InchesToPoints(0.512)'[5]
.FooterMargin = Application.InchesToPoints(0.512)'[6]
.CenterHorizontally = False '[7]
.CenterVertically = False '[8]
End With
・上記の[番号]は左図のNoを示す。
・センチ指定したい場合は、
"CentimetersToPoints" で行う。
・中央印刷は余白からの中央寄せとなる
[6] ペ−ジの指定

With ActiveSheet.PageSetup
.Orientation = xlPortrait '[1]
.Zoom = 100 '[2]
.PaperSize = xlPaperA4 '[3]
.PrintQuality = 300 '[4]
.FirstPageNumber = xlAutomatic'[5]
End With
-------------------------------------------------------------
下記は自動的に縮小し1枚に収まる。

With ActiveSheet.PageSetup
.Zoom = False
.FitToPagesWide = 1 '[6]
.FitToPagesTall = 1 '[7]
End With
[7] その他のシ−ト指定

With ActiveSheet.PageSetup
.PrintGridlines = False '[1]
.PrintNotes = False '[2]
.Draft = False '[3]
.BlackAndWhite = False '[4]
.PrintHeadings = False '[5]
.Order = xlDownThenOver '[6]、[7]は= xloverThenDown
End With
【戻る】 【Top画面】 【HPへ】