Excel VBA Print: How to Print Sheets and Workbooks

VBA & macros · Updated November 3, 2026

Excel VBA Print: How to Print Sheets and Workbooks

To print from Excel VBA, call an object’s PrintOut method: for example, ThisWorkbook.Worksheets("Report").PrintOut sends the Report sheet to the active printer. Use PrintPreview to review the output first, and set the worksheet’s page layout when you need control over what fits on each page.

What Excel VBA Print Means

Excel’s PrintOut method prints a workbook, worksheet, chart, or range through the printer selected in Excel. The method can also specify options such as the page or page range, number of copies, collation, and whether to preview rather than print. If you omit those options, Excel uses its defaults and the current print settings.

VBA does not create a separate kind of print output: it automates Excel’s normal printing process. The worksheet’s print area, page orientation, scaling, margins, paper size, and the printer driver can all affect the result. A macro that works on one computer may therefore paginate differently on another computer with a different printer or driver.

Printing is also different from exporting a PDF. Use PrintOut when the goal is paper or a printer queue. For a file that can be reviewed or shared without sending a job to a printer, Excel’s PDF export features may be a better fit.

Print a Worksheet, Range, or Workbook

Choose the narrowest object that matches the job. A worksheet call prints a sheet using its print settings; a range call targets a particular block; and a workbook call is appropriate when the intended job is the workbook’s printable contents. The examples below print immediately, so save a copy of the workbook before running a macro. VBA actions cannot be undone with Ctrl+Z.

  • One worksheet: call PrintOut on the worksheet.
  • A cell range: call PrintOut on the range you want printed.
  • A workbook: call PrintOut on the workbook, after checking which sheets and print areas it contains.

For example, with a worksheet named Report and data in A1:G35, the following macro prints just that range. Open the Visual Basic Editor, choose Insert > Module, and place the procedure in the module. On Windows, Alt+F11 opens the editor; on Mac, use Option+F11, or the corresponding Fn combination if your keyboard requires it.

Sub PrintReportRange()
    Dim ws As Worksheet
    Dim printBlock As Range

    ' Identify the report and the cells to print.
    Set ws = ThisWorkbook.Worksheets("Report")
    Set printBlock = ws.Range("A1:G35")

    ' Send the selected range to the active printer.
    printBlock.PrintOut Copies:=1, Collate:=True
End Sub

The code assumes that the sheet exists and that its name is spelled exactly as shown. If the worksheet is renamed, update the string in the macro. To print the whole sheet instead, use ws.PrintOut Copies:=1; to target the workbook, use ThisWorkbook.PrintOut Copies:=1. Check the job before using the workbook-level form, because it can produce far more pages than a single-sheet call.

Preview Before Sending a Print Job

A print preview is a useful check for clipped columns, unexpected blank pages, and awkward page breaks. In VBA, PrintPreview opens Excel’s preview for the selected object. For example, after setting ws to the intended worksheet, use ws.PrintPreview. The preview lets a person inspect the result before deciding whether to print.

You can also use the Preview argument of PrintOut when you want the method to display a preview instead of sending the job straight to the printer:

Sub PreviewReport()
    Dim ws As Worksheet

    ' Select the worksheet whose layout needs review.
    Set ws = ThisWorkbook.Worksheets("Report")

    ' Display a preview rather than printing immediately.
    ws.PrintOut Preview:=True
End Sub

For an interactive print dialog, VBA can show Excel’s built-in Print dialog with Application.Dialogs(xlDialogPrint).Show. That is different from calling PrintOut without the preview option: the dialog allows the user to review or change print choices before submitting a job.

Set the Print Area and Page Layout

A print area defines the cells Excel should treat as the printable region on a worksheet. Set it before printing when a report occupies only part of a sheet. Page setup controls how that region is placed on paper. The following example sets the report area to A1:G35, switches to landscape, and scales the width to one page while allowing the report to use as many pages vertically as needed.

Sub SetUpAndPrintReport()
    Dim ws As Worksheet

    ' Save a separate copy before running; printing and page setup changes are not undone with Ctrl+Z.
    Set ws = ThisWorkbook.Worksheets("Report")

    ' Define the printable cells and fit the width to one page.
    With ws.PageSetup
        .PrintArea = "$A$1:$G$35"
        .Orientation = xlLandscape
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 0
    End With

    ' Print using the worksheet's defined print area.
    ws.PrintOut Copies:=1, IgnorePrintAreas:=False
End Sub

Setting Zoom to False allows the fit-to-pages settings to control scaling. A width of one page can make text smaller, particularly when the selected area has many columns. If readability matters more than keeping the width to one page, leave more pages across or use a larger paper size where available. Check the preview because the printer’s supported paper sizes and margins can influence the final layout.

A print area belongs to a worksheet, so it can affect later manual printing too. If the macro should no longer restrict that sheet, clear it with ws.PageSetup.PrintArea = "". Be deliberate: clearing it changes the sheet’s print setup, not just the current job.

Choose PrintOut Options

The arguments to PrintOut are optional. Named arguments make code easier to understand and reduce the chance of assigning a value to the wrong position. Common options include:

  • From and To specify a page range, such as pages 2 through 4 of the object’s output.
  • Copies sets the number of copies to send.
  • Preview displays a preview instead of immediately printing.
  • ActivePrinter can select a printer by its Excel-recognized name. Printer names and port details can differ between computers.
  • Collate controls the order of multiple copies when more than one page is printed.
  • IgnorePrintAreas controls whether Excel honors the worksheet’s set print area.

For instance, ws.PrintOut From:=2, To:=4, Copies:=2, Collate:=True requests two collated copies of pages 2 to 4. Those page numbers refer to the pages Excel generates from the current layout, not necessarily to worksheet tabs or rows. If pagination changes after a layout edit, the same page range may contain different content.

Common Problems and How to Diagnose Them

If a macro runs but nothing appears on paper, first check Excel’s active printer and the operating system’s print queue. A printer may be offline, paused, or unavailable. If you specify ActivePrinter, verify that the name matches what Excel recognizes on that computer; hard-coding a printer name makes a macro less portable.

If the output has extra pages, inspect the used area, print area, scaling, and page breaks. Formatting applied far below or to the right of the visible report can affect the apparent used range. In Excel for Microsoft 365 on Windows, use File > Print to inspect the preview and page count. Adjust the print area or page setup rather than deleting content blindly.

If text is too small, forcing a wide table onto one page is often the cause. Consider landscape orientation, a smaller print area, repeated headings, or allowing additional pages across. If one page is blank, look for manual page breaks, a print area that excludes the expected cells, or an object that extends the printable region. Preview each change before rerunning a large job.

Errors such as “Subscript out of range” commonly mean the worksheet name in the code does not match a tab in the workbook. A macro that cannot be run may also be blocked by macro security or saved in a format that does not preserve VBA. Use a macro-enabled workbook such as .xlsm when the code must remain in the file, and only enable macros from sources you trust.

Windows, Mac, and Excel for the Web

Excel VBA is available in the desktop editions of Excel for Windows and Mac, though printer setup, dialog behavior, keyboard shortcuts, and printer naming can differ. A macro that refers to a Windows-specific printer name or file path should not be assumed to work unchanged on Mac. Keep printer selection configurable when a workbook will be shared across operating systems.

Excel for the web does not run VBA macros. A workbook containing VBA can be opened there, but printing through VBA requires desktop Excel. The web app can print through its own interface, subject to its available features and the browser’s print process. For teams using both desktop and web Excel, document the desktop requirement and provide a manual printing route where practical.

VBA Printing Compared with Manual Printing and PDF

Manual printing is usually preferable for a one-off job because the user can select sheets, copies, and printer options in the dialog. VBA becomes useful for repeatable work: for example, printing a standard report after refreshing data, applying a known print area, or producing several recurring outputs with consistent settings.

Automation also increases the consequences of a mistaken setting. A loop that prints one report per customer can send a large number of jobs, and printing directly to paper can waste supplies if a range or copy count is wrong. Preview first, test with one copy, and consider PDF export when the desired result is a file to review or distribute. A PDF is not a print job; it can be inspected before anyone chooses to print it.

Frequently Asked Questions

What is the VBA command to print an Excel sheet?
Use Worksheets("SheetName").PrintOut, replacing SheetName with the exact worksheet tab name. The call sends the sheet to Excel’s active printer unless you provide other options.

How do I print only a selected range with VBA?
Set a Range variable to the cells you want, then call that range’s PrintOut method. You can also define a worksheet print area when the same region should be used repeatedly.

How do I preview a worksheet before printing in VBA?
Call PrintPreview on the worksheet or use PrintOut Preview:=True. Both let you review the paginated output before sending it to the printer.

Can Excel VBA print to PDF?
VBA printing normally sends output to a printer. To create a PDF, use Excel’s PDF export functionality rather than treating a regular PrintOut call as a PDF export; the exact export approach depends on whether the target is a sheet or workbook.

Can I run a VBA print macro in Excel for the web?
No. Excel for the web does not execute VBA. Open the workbook in desktop Excel for Windows or Mac to run the macro, or use the web app’s manual print option.

Can I undo a VBA print macro with Ctrl+Z?
No. Excel’s undo history does not reverse VBA actions, and it cannot recall a print job already sent to a queue. Save a copy, preview first, and use a small test job before automating larger print runs.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.