How to Print Data with Excel VBA (A Detailed Guideline)

Download Practice Workbook


Step 1 – Opening the VBA Editor to Print in Excel

Press ALT+F11 to open the Visual Basic Editor.

Opening VBA Editor to Print Data with VBA in Excel

Read More: How to Set Print Area in Excel (5 Methods)


Step 2 – Inserting a New Module to Print in Excel

Go to the Insert option in the VBA toolbar. Click Insert > Module to open a new module.

Read More: How to Print Gridlines in Excel (2 Ways)


Step 3 – Entering the VBA Code to Print in Excel

A new module named Module1 will open. Enter the following VBA code.

⧭ VBA Code:

Sub VBA_Print()

ActiveWorkbook.ActiveSheet.PrintOut copies:=1

End Sub

VBA Code to Print Data with VBA in Excel

⧭ Notes:

  • I want to print the active worksheet of my workbook. To print any other worksheet, enter the name of the worksheet directly in the code.

To print out the worksheet called Sheet1, use:

ActiveWorkbook.Worksheets(“Sheet1”).PrintOut copies:=1

  • You can also print from a workbook that’s not active. To print out Sheet1 from a workbook called Workbook1, use:

Workbook(“Workbook1”).Worksheets(“Sheet1”).PrintOut copies:=1

  • We are printing only one copy of the worksheet. If you want to print more than one copy, change the copies
  • To print multiple worksheets and collate them while printing, the PrintOut function of VBA has a property called Collate. Set it to be True.

ActiveWorkbook.ActiveSheet.PrintOut copies:=10, Collate:=True

Read More: Excel VBA: How to Set Print Area Dynamically (7 Ways)


Similar Readings


Step 4 – Running the VBA Code to Print in Excel

Run the Macro by clicking the Run option in the VBA toolbar.

Running Code to Print Data with VBA in Excel

Read More: Excel VBA: Set Print Area for Multiple Ranges (5 Examples)


Step 5 – The Final Output: Print with VBA

The worksheet is printed and a window opens.

Read More: Excel VBA: Print Range of Cells (5 Easy Methods)


Things to Remember

We’ve used the PrintOut function of VBA. There’s another function in VBA called PrintPreview, that shows the preview of the data before printing.

The syntax of the PrintPreview function is the same as the PrintOut function, use PrintPrview in place of PrintOut.

ActiveWorkbook.ActiveSheet.PrintPreview

It’ll show the preview of your worksheet before printing.

Preview of Print through Excel VBA

 


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Rifat Hassan
Rifat Hassan

Rifat Hassan, BSc, Electrical and Electronic Engineering, Bangladesh University of Engineering and Technology, has worked with the ExcelDemy project for almost 2 years. Within these 2 years, he has written over 250 articles. He has also conducted a few Boot Camp sessions on effective coding, especially Visual Basic for Applications (VBA). Currently, he is working as a Software Developer to develop and deploy additional add-ins to enhance the customers with a more sophisticated experience with Microsoft Office Suits,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo