How to Display Print Preview with Excel VBA (3 Macros)

Before printing worksheets, it’s safe to check the print preview for the worksheets so that no errors remain and how they will look after printing. Excel VBA offers some quick and smart ways to do that. Hope this article will be a quick guide to display a print preview in Excel VBA.


Download Practice Workbook

You can download the free Excel template from here and practice on your own.


3 VBA Macros to Display Print Preview in Excel

To explore the methods, we’ll use the following dataset which represents some salesperson sales in different regions.


1. VBA Macro to Display Print Preview for the Active Sheet

Firstly, we’ll learn how to display a print preview for the current working active sheet.

  • Right-click on the sheet title.
  • Then select View Code from the context menu.

Soon after, a VBA window will appear. Or you can press Alt+F11 to open the VBA window directly.

VBA Macro to Display Print Preview for the Active Sheet

  • Later, type the following codes in it-
Sub PrintPreview_ActiveSheet()
ActiveSheet.PrintPreview
End Sub
  • Then press the Run icon to run the codes and consequently you will get a Macros dialog box.

VBA Macro to Display Print Preview for the Active Sheet

  • At this moment, select the Macro Name as mentioned in the above codes.
  • Finally, just press Run.

VBA Macro to Display Print Preview for the Active Sheet

Soon after a Print Preview window will open up.

Read More: How to Set Print Preview in Excel (6 Options)


2. VBA Macro to Display Print Preview for Specific Worksheet in Excel

We can display a print preview for any specific sheet by mentioning its name in the VBA codes. You will learn that in this method. I have set the name ‘Specific Sheet’ for the worksheet used in this method.

  • Open the VBA window by selecting View Code from the context menu after right-clicking on the sheet title.

VBA Macro to Display Print Preview for Specific Worksheet in Excel

  • After that, 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.

VBA Macro to Display Print Preview for Specific Worksheet in Excel

  • Select the specified Macro Name from the dialog box.
  • Finally, just press Run.

VBA Macro to Display Print Preview for Specific Worksheet in Excel

Then you will get the Print Preview window like the image below.

Related Content: How to Print Excel Spreadsheet on Multiple Pages (3 Ways)


Similar Readings


3. VBA Macro to Display Print Preview for the Selected Worksheets

In the previous methods, we learned to display a print preview for a single worksheet. In this method, you will learn to display a print preview for multiple worksheets at a time.

  • Open the VBA window for this sheet, like the previous methods.

VBA Macro to Display Print Preview for the Selected Worksheets

  • Then 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.

VBA Macro to Display Print Preview for the Selected Worksheets

  • Select the Macro Name as mentioned in the above codes and then just press Run.

VBA Macro to Display Print Preview for the Selected Worksheets

Soon after you will get the print preview for the currently selected sheet only.

VBA Macro to Display Print Preview for the Selected Worksheets

  • Now to get the print preview for multiple sheets, close the preview and minimize the VBA window then just go back to your workbook and select the multiple sheets using your mouse by pressing and holding the Ctrl key on your keyboard.

VBA Macro to Display Print Preview for the Selected Worksheets

  • Then again go to that VBA window and now run the codes by clicking the Run icon.

VBA Macro to Display Print Preview for the Selected Worksheets

  • Select the same Macro Name again.

  • Now have a look that 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.

Related Content: How to Print All Sheets in Excel (3 Methods)


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.

Conclusion

I hope the procedures described above will be well enough to display a print preview in Excel VBA. Feel free to ask any question in the comment section and please give me feedback.


Related Articles

Mithun

Mithun

Hello! I am Md. Sourov Hossain Mithun. Welcome to my profile. Currently, I am working at Exceldemy as an Excel and VBA Content Developer. Excel is amazing software. Here I will post excel related useful articles. I am a graduate of Bangladesh University of Engineering and Technology. I love to learn new things and work with them. Thank you.

We will be happy to hear your thoughts

Leave a reply

ExcelDemy
Logo