Method 1 – VBA Macro to Display Print Preview for the Active Sheet
- Right-click on the sheet title.
- Select View Code from the context menu.
A VBA window will appear. Or you can press Alt+F11 to open the VBA window directly.
- Type the following codes in it-
Sub PrintPreview_ActiveSheet()
ActiveSheet.PrintPreview
End Sub
- Press the Run icon to run the codes, and consequently, you will get a Macros dialog box.
- Select the Macro Name as mentioned in the above codes.
- Press Run.
Print Preview window will open up.
Method 2 – VBA Macro to Display Print Preview for Specific Worksheet in Excel
- Open the VBA window by selecting View Code from the context menu after right-clicking on the sheet title.
- Write the following codes in the VBA window-
Sub PrintPreview_SpecificSheet()
Worksheets("Specific Sheet").PrintPreview
End Sub
- Press the Run icon and the Macros dialog box will appear.
- Select the specified Macro Name from the dialog box.
- Press Run.
You will get the Print Preview window like the image below.
Method 3 – VBA Macro to Display Print Preview for the Selected Worksheets
- Open the VBA window for this sheet, like the previous methods.
- Write the following codes in the VBA window-
Sub PrintPreview_SelectedSheets()
ActiveWindow.SelectedSheets.PrintPreview
End Sub
- Press the Run icon to run the codes and open the Macros dialog box.
- Select the Macro Name as mentioned in the above codes, and then just press Run.
Soon after you will get the print preview for the currently selected sheet only.
- Get the print preview for multiple sheets, close the preview and minimize the VBA window, go back to your workbook, and select the multiple sheets using your mouse by pressing and holding the Ctrl key on your keyboard.
- Go to that VBA window and run the codes by clicking the Run icon.
- Select the same Macro Name again.
- The Print Preview window shows the preview of the first worksheet. To see the other previews just press Next Page.
It’s the preview of another worksheet.
Things to Remember
- The VBA operations can be operatable after making Macros for the source data.
- Make sure there are no spaces between the functions.
- VBA function can directly be accessed by Alt+F11.
- Make sure that you have clicked the same worksheet whose Print Preview you want before typing the Activesheet function in the VBA window.
Download Practice Workbook
You can download the free Excel template from here and practice on your own.
Related Articles
- Excel VBA: Print Preview for Selected Range
- Excel VBA: How to Set Print Area Dynamically
- How to Set Print Area to Selection Using VBA in Excel
- Excel VBA: Set Print Area for Multiple Ranges
- VBA Code for Print Button in Excel
- Excel VBA: Print Range of Cells