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.


How to Display Print Preview in Excel: 3 VBA Macros

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.


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.

Read More: How to Print Specific Sheets Using VBA Macro in Excel


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.


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.


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

Get FREE Advanced Excel Exercises with Solutions!

Tags:

Md. Sourov Hossain Mithun
Md. Sourov Hossain Mithun

Md. Sourov Hossain Mithun, an Excel and VBA Content Developer at Softeko's ExcelDemy project, joined in October 2021. Holding a Naval Architecture & Marine Engineering degree from BUET, Mithun showcases expertise during his two-year tenure. With over 200 published articles on Excel topics, he earned a promotion to Team Leader, excelling in leading diverse teams. Mithun's passion extends to Advanced Excel, Excel VBA, Data Analysis, and Python programming, contributing significantly to the innovative and dynamic environment of ExcelDemy... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo