[Excel VBA] Macro to Automatically Print a Specific Sheet (Printing Sheet1)

目次

Background

I often encounter situations where I need to print specific Excel files regularly.

Thinking, “It would be convenient to print with a single click without opening the print settings every time,” I wrote a VBA macro to automatically print “Sheet1”.

Specifications After Execution

When this macro is executed, it performs the following:

  1. Automatically prints “Sheet1” in the Excel workbook.
  2. Sets the print orientation to Portrait and scales the content to fit on one page.
  3. Displays a message box upon completion.

VBA Code

Below is the macro I actually use.

Sub PrintOrderList()
    Dim ws As Worksheet

    ' Specify the sheet to print
    Set ws = ThisWorkbook.Sheets("Sheet1")

    ' Print Settings
    With ws.PageSetup
        .Orientation = xlPortrait           ' Print Portrait
        .Zoom = False                       ' Disable manual scaling
        .FitToPagesWide = 1                 ' Fit to 1 page wide
        .FitToPagesTall = 1                 ' Fit to 1 page tall
    End With

    ' Execute Print
    ws.PrintOut

    MsgBox "Sheet1 has been printed."
End Sub

Tips for Customization

  • Change Sheet Name: By changing "Sheet1" to another sheet name, you can set any sheet as the print target.
  • Page Layout: You can support landscape printing or multi-page printing by modifying the properties within PageSetup.
  • Print Preview: If you want to check the preview before printing, use .PrintPreview instead of .PrintOut.
ws.PrintPreview ' Change to this if you want to see the preview first

Summary

  • You can create a simple macro in VBA to automatically print Excel sheets.
  • It helps improve efficiency by eliminating the need to adjust print settings every time.
  • It can be adapted to handle multiple sheets or specific print ranges.

Being able to execute routine printing tasks with a single click is very convenient for daily work. Please give it a try.

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

私が勉強したこと、実践したこと、してることを書いているブログです。
主に資産運用について書いていたのですが、
最近はプログラミングに興味があるので、今はそればっかりです。

目次