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 codeUsing Excel VBA CodeVBA code refers to a set of instructions written by the user in the Visual Basic Applications programming language on a Visual Basic Editor (VBE) to perform a specific task.read more, we can print the whole worksheet data. For example, we can print the workbookPrint The WorkbookThe print feature in excel is used to print a sheet or any data. While we can print the entire worksheet at once, we also have the option of printing only a portion of it or a specific table.read more, 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.

[From]: 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.

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

[Copies]: How many copies do you need to print?

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

You are free to use this image on you website, templates, etc., Please provide us with an attribution linkHow to Provide Attribution?Article Link to be HyperlinkedFor eg:Source: VBA Print (wallstreetmojo.com)

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.

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

Now, access the PrintOut method.

Sub Print_Example1()

Range(“A1:D14”).PrintOut

End Sub

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.

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 to Print the Entire Worksheet.

Sub Print_Example1()

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

End Sub

  • Code to Refer the Sheet Name.

Code to Refer the Sheet Name.

Sub Print_Example1()

Sheets(“Ex 1”).UsedRange.PrintOut ‘This will also print the entire used range of the sheet called Ex 1.

End Sub

  • Code to Print all the Worksheets in the Workbook.

Code to Print all the Worksheets in the Workbook.

Sub Print_Example1()

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

End Sub

  • Code to Print the Entire Workbook Data.

Code to Print the Entire Workbook Data.

Sub Print_Example1()

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

End Sub

  • Code to Print Only the Selected Area.

Code to Print Only the Selected Area.

Sub Print_Example1()

Selection.PrintOut ‘This will print only the selected range

End Sub

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.

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

Sub Print_Example2()

Range (“A1:S29”)

End Sub

Now, select the PrintOut method.

Sub Print_Example2()

Range(“A1:S29”).PrintOut

End Sub

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.

Sub Print_Example2()

Range(“A1:S29”).PrintOut Preview:=True

End Sub

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

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.

Sub Print_Example2()

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

ActiveSheet.PrintOut Preview:=True

End Sub

It will set up the page to print in one sheet and landscape mode. So, now the print previewPrint PreviewPrint preview in Excel is a tool used to represent the print output of the current page in the excel to see if any adjustments need to be made in the final production. Print preview only displays the document on the screen, and it does not print.read more will be like this.

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: –

  • Print Titles in ExcelPrint Area in ExcelPrint Excel GridlinesPrint Comments in Excel