How to use print preview in VBA (With Examples)

Print preview in VBA can be used to view the output of a document or form before actually sending it to the printer. This can be useful for debugging and for checking that the formatting is correct. To use print preview in VBA, the user must first select the Print Preview Menu item from the File menu. The user can then browse through the document or form and adjust settings such as font size and margins. The user can also use the Print button on the Preview window to print the document or form. Finally, the user can close the print preview window once the document has been printed or saved.


You can use the following methods in VBA to display a print preview before actually printing a sheet:

Method 1: Print Preview for Entire Sheet

Sub UsePrintPreview()
ActiveSheet.PrintPreview
End Sub

This particular macro will provide a print preview for the entire currently active sheet.

Method 2: Print Preview for Selected Area

Sub UsePrintPreview()
Selection.PrintPreview
End Sub

This particular macro will provide a print preview for only the currently selected area of the sheet.

The following examples show how to use each method with the following active sheet in Excel:

Example 1: Print Preview for Entire Sheet

Suppose we would like to print the entire active sheet.

We can create the following macro to perform a print preview to see what the printed page will look like before we actually print it:

Sub UsePrintPreview()
ActiveSheet.PrintPreview
End Sub

When we run this macro, the following print preview window appears:

This shows us exactly what the page will look like if we print the entire currently active sheet.

Example 2: Print Preview for Selected Area

We can create the following macro to perform a print preview to see what this selected area will look like on a page before we actually print it:

Sub UsePrintPreview()
Selection.PrintPreview
End Sub

When we run this macro, the following print preview window appears:

This shows us exactly what the page will look like if we print only the selected area.

Note: You can find the complete documentation for the PrintPreview method in VBA .

VBA: How to Print to PDF

x