How to Use Print Preview in VBA (With Examples)


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

Suppose we select the cell range A1:C4 and only want to print this 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 here.

Additional Resources

The following tutorials explain how to perform other common tasks in VBA:

VBA: How to Print to PDF
VBA: How to Create Folders
VBA: How to Delete Folders
VBA: How to Delete Files

Leave a Reply

Your email address will not be published. Required fields are marked *