Excel VBA 印刷エリアの設定マクロについて


こんにちは脇村です。僕のブログでは、本業での実務上のEXCEL、ACCESSマクロ&VBAの使えそうなコードの紹介、コールドリーディングの実践例、電話占いでの現場、最近読んでいいなと思った本等について、主に発信していきたいと思っています。

今回はEXCELVBAについて発信したいと思います。 こういったプログラム系統は何を実現したいかを強く頭に描くことが実現への第一歩につながると思います。 少しずつ発信していってその手助けができれば幸いだと思っています。 今回はEXCELVBA印刷エリアの設定マクロについてです。 現在のsheetを1ページに収めると言うVBAです。

Sub Macro1()  
Sheets(“ネギトロ”).PageSetup.PrintArea = “$A$1:$S$85”  ①  
With Sheets(“ネギトロ”).PageSetup ①
.Orientation = xlLandscape  ②  
.PaperSize = xlPaperA4  ③    
.Zoom = False  ④       
.FitToPagesWide = 1   ⑤      
.FitToPagesTall = 1     ⑥
End With  ⑦
End Sub

マクロの記録を使うと下記の様に記録されます。

Sub Macro1()    
Application.CutCopyMode = False    
Application.PrintCommunication = False    
With ActiveSheet.PageSetup        
.PrintTitleRows = “”        
.PrintTitleColumns = “”    
End With    
Application.PrintCommunication = True    
ActiveSheet.PageSetup.PrintArea = “”    
Application.PrintCommunication = False    
With ActiveSheet.PageSetup        
.LeftHeader = “”        
.CenterHeader = “”        
.RightHeader = “”        
.LeftFooter = “”        
.CenterFooter = “”        
.RightFooter = “”        
.LeftMargin = Application.InchesToPoints(0.708661417322835)        
.RightMargin = Application.InchesToPoints(0.708661417322835)        
.TopMargin = Application.InchesToPoints(0.748031496062992)         .BottomMargin = Application.InchesToPoints(0.748031496062992)         .HeaderMargin = Application.InchesToPoints(0.31496062992126)         .FooterMargin = Application.InchesToPoints(0.31496062992126)         .PrintHeadings = False        
.PrintGridlines = False        
.PrintComments = xlPrintNoComments        
.PrintQuality = 600        
.CenterHorizontally = False        
.CenterVertically = False        
.Orientation =xlLandscape ② 横型:xlLandscape 縦型:xlportrait        
.Draft = False        
.PaperSize = xlPaperA4 ③ A4サイズ        
.FirstPageNumber = xlAutomatic        
.Order = xlDownThenOver        
.BlackAndWhite = False        
.Zoom = False ④ 拡大/縮小        
.FitToPagesWide = 1 ⑤ ページ指定最初        
.FitToPagesTall = 1 ⑥ ページ指定最後        
.PrintErrors = xlPrintErrorsDisplayed        
.OddAndEvenPagesHeaderFooter = False        
.DifferentFirstPageHeaderFooter = False        
.ScaleWithDocHeaderFooter = True        
.AlignMarginsHeaderFooter = True        
.EvenPage.LeftHeader.Text = “”        
.EvenPage.CenterHeader.Text = “”        
.EvenPage.RightHeader.Text = “”        
.EvenPage.LeftFooter.Text = “”        
.EvenPage.CenterFooter.Text = “”        
.EvenPage.RightFooter.Text = “”        
.FirstPage.LeftHeader.Text = “”        
.FirstPage.CenterHeader.Text = “”        
.FirstPage.RightHeader.Text = “”    
End With    
Application.PrintCommunication = True
End Sub

上記のコードで必要なのは①~⑦です。 他のコードは削除しても構いません。 ①のエリアは手でコードを打って設定しなおしてください。 今回は印刷エリア設定マクロでした。次回のブログもまたよろしくお願いします。

——————————————————————————————

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 パワフルで高速なピュアSSDクラウドレンタルサーバー
  https://px.a8.net/svt/ejp?a8mat=3NA5PS+BRWNHU+3JTE+61Z83
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━


関連記事
Excel VBA 印刷マクロについて


コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA