VBA Print

Last Updated :

21 Aug, 2024

Blog Author :

Edited by :

Ashish Kumar Srivastav

Reviewed by :

Dheeraj Vaidya, CFA, FRM

Table Of Contents

arrow

Print in VBA is very similar to print in Excel. When we have important data in Excel or spreadsheets, then the only way to have them safe is to save them to PDF or print them. For print, we need to set up the print command in VBA first before using it. What this command does is print or write the data into another file.

What is Print in VBA Excel?

VBA Printout is nothing, but as usual, how we print in the regular worksheet. There is no difference in this. Using Excel VBA code, we can print the whole worksheet data. For example, we can print the workbook, charts, specified range, etc.

After all our hard work in presenting the report to the manager, we usually send emails. But sometimes, your manager needs a hard copy of your reports in the meeting. In those scenarios, you need to print the report you have in the spreadsheet. One of the reasons your manager needs a printout of the report could be a very large report to read on the computer. In a worksheet, you must be already familiar with printing the reports. This article will show you how to print using VBA coding. Follow this article for the next 15 minutes to learn how to print reports in VBA.

Syntax of VBA PrintOut in VBA Excel

Before we see the syntax, let me clarify this first. What do we print? We print ranges, charts, worksheets, and workbooks. So, the PrintOut () method is available with all these objectives.

vba printout function

: From which page of the printing has to start? It will be treated as from the first page if we do not supply any value.

: What should be the last page to print? If ignored, it will print till the last page.

: How many copies do you need to print?

: Would you like to see the print preview before proceeding to print? If yes, TRUE is the argument. If not, FALSE is the argument.

VBA Print

Examples of Print in VBA Excel

Below are the examples of Print in VBA Excel.

We have created dummy data for illustration purposes, as shown in the picture below.

vba printout example 1.1

Now, we need to print the report from A1 to D14. It is our range. Enter the range in the VBA code to access the PrintOut method.

Code:

Sub Print_Example1()

Range ("A1:D14")

End Sub
vba printout example 1.2

Now, access the PrintOut method.

Code:

Sub Print_Example1()

Range("A1:D14").PrintOut

End Sub
vba printout example 1.3

We are not touching any of the parameters. It is enough to print the selected range. If we run this code, it will print the range from A1 to D14 cell.

Parameters of Printout Method in VBA Excel

Now, we have copied and pasted the same data to use other parameters of the PrintOut method in VBA Excel.

vba printout example 3.7

When we want to print the entire sheet, we can refer to the entire sheet as Active Sheet. It is because it will cover the entire sheet in it.

  • Code to Print the Entire Worksheet.

Code:

Sub Print_Example1()

ActiveSheet.UsedRange.PrintOut
'This will print the entire sheet used range.

End Sub
example 2.1
  • Code to Refer the Sheet Name.

Code:

Sub Print_Example1()

Sheets("Ex 1").UsedRange.PrintOut
'This will also print the entire used range of the sheet called Ex 1.

End Sub
example 2.2
  • Code to Print all the Worksheets in the Workbook.

Code:

Sub Print_Example1()

Worksheets.UsedRange.PrintOut
'This will also print the entire used range of all the sheet in the workbook.

End Sub
example 2.3
  • Code to Print the Entire Workbook Data.

Code:

Sub Print_Example1()

ThisWorkbook.UsedRange.PrintOut
'This will also print the entire used range of all the sheet in the workbook.

End Sub
Example 2.4
  • Code to Print Only the Selected Area.

Code:

Sub Print_Example1()

Selection.PrintOut
'This will print only the selected range

End Sub
print in vba excel Example 2.5

How to use the Parameters of Print Out Method in Excel VBA?

Now, we will see how to use the parameters of the PrintOut method. As we told you, we expanded the data to use other properties.

vba printout example 3.7

For sure, this is not going to print on a single sheet. Select the range as A1 to S29.

Code:

Sub Print_Example2()

Range ("A1:S29")

End Sub
vba printout example 3.1

Now, select the PrintOut method.

Code:

Sub Print_Example2()

Range("A1:S29").PrintOut

End Sub
vba printout example 3.2

The first and second parameters are From & To, and what is the starting and ending pages position. It will print all the pages by default, so we do not touch this part. Next, we want to see the print preview so that we will choose the preview as TRUE.

Code:

Sub Print_Example2()

Range("A1:S29").PrintOut Preview:=True

End Sub
vba printout example 3.3

Now, we will run this code. First, we will see the print preview.

vba printout example 3.6

This is coming in 2 pages.

So first, we want to set up the page to come in a single sheet. Use the below code to set up the page to come in one sheet.

Code:

Sub Print_Example2()

With Worksheets("Example 1").PageSetup
.Zoom = False
.FitToPagesTall = 2
.FitToPagesWide = 1
.Orientation = xlLandscape
End With

ActiveSheet.PrintOut Preview:=True

End Sub
print in vba excel Example 3.5

It will set up the page to print in one sheet and landscape mode. So, now the print preview will be like this.

Example 3.4

Like this, we can use the VBA PrintOut method to print the things we want to print and play around with them.

This article is a guide to VBA Print Statement. Here, we discuss using Excel VBA code for printouts, examples, and step-by-step explanations. You can learn more about Excel VBA from the following articles: -