WallStreetMojo

WallStreetMojo

WallStreetMojo

MENUMENU
  • Free Tutorials
  • Certification Courses
  • Excel VBA All in One Bundle
  • Login
Home » Excel, VBA & Power BI » Learn VBA » VBA Print

VBA Print

Print in VBA is very similar to the 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 if prints or writes 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. We can print the workbook, charts, specified range, etc.

After all the hard work we have done to present the report to the manager, we usually send emails. But in some cases in the meeting, your manager needs a hard copy of your reports. In those scenarios, you need to print the report you have in the spreadsheet. One of the reasons your manager needs a print out of the report could be a very large report to read on the computer. In a worksheet, you must have already familiar with printing the reports. In this article, we 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, workbooks. So PrintOut () method is available with all these objectives.

vba printout function

[From]: From which page of the printing has to start. If we don’t supply any value, it will treat as from the first page.

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

[Copies]: How many copies you need to print.

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

Popular Course in this category
Sale
VBA Training (3 Courses, 12+ Projects)
4.6 (247 ratings)
3 Courses | 12 Hands-on Projects | 43+ Hours | Full Lifetime Access | Certificate of Completion
View Course

vba-print

Examples of Print in VBA Excel

Below are the examples of Print in VBA Excel.

You can download this VBA Print Excel Template here – VBA Print Excel Template

For illustration purposes, I have created dummy data, as shown in the below picture.

vba printout example 1.1

Now we need to print the report from A1 to D14. This is my 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

I am not touching any of the parameters. This is enough to print the selected range. If I run this code, it will print the range from A1 to D14 cell.

Parameters of Printout Method in VBA Excel

Now I 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. This 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 print out method. As I told, I had expanded the data to use other properties.

vba printout example 3.7

For sure, this is not going to print in 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 print out method.

Code:

Sub Print_Example2()

Range("A1:S29").PrintOut

End Sub

vba printout example 3.2

The first & second parameters are From & To, what is the starting & ending pages position. By default, it will print all the pages, so I don’t touch this part. Now I want to see the print preview, so I will choose Preview as TRUE.

Code:

Sub Print_Example2()

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

End Sub

vba printout example 3.3

Now I will run this code. We will see the print preview.

vba printout example 3.6

This is coming in 2 pages.

So first, I 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

This will set up the page to print in one sheet as well to print in landscape mode. Now the print preview will be like this.

Example 3.4

Like this, we can use VBA print out a method to print the things we wanted to print and play around with them.

Recommended Articles

This has been a Guide to VBA Print Statement. Here we discuss how to use Excel VBA Code for printout along with examples and step by step explanations. You can learn more about Excel VBA from the following articles

  • Print Titles in Excel
  • Print Area in Excel
  • Print Excel Gridlines
  • Print Comments in Excel
8 Shares
Share
Tweet
Share
VBA Training (3 Courses, 12+ Projects)
  • 3 Courses
  • 12 Hands-on Projects
  • 43+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>
Primary Sidebar
Footer
COMPANY
About
Reviews
Contact
Privacy
Terms of Service
RESOURCES
Blog
Free Courses
Free Tutorials
Investment Banking Tutorials
Financial Modeling Tutorials
Excel Tutorials
Accounting Tutorials
Financial Statement Analysis
COURSES
All Courses
Financial Analyst All in One Course
Investment Banking Course
Financial Modeling Course
Private Equity Course
Venture Capital Course
Excel All in One Course

Copyright © 2021. CFA Institute Does Not Endorse, Promote, Or Warrant The Accuracy Or Quality Of WallStreetMojo. CFA® And Chartered Financial Analyst® Are Registered Trademarks Owned By CFA Institute.
Return to top

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Book Your One Instructor : One Learner Free Class
Let’s Get Started
Please select the batch
Saturday - Sunday 9 am IST to 5 pm IST
Saturday - Sunday 9 am IST to 5 pm IST

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Login

Forgot Password?

WallStreetMojo

Download VBA Print Excel Template

New Year Offer - VBA Training Course (6 courses, 35+ hours video) View More