VBA Print: Get Your Visual Basic Application to Print for You
Visual Basic for Application, which is commonly referred to as VBA, is one of the easiest programming languages to pick up on. Created by Microsoft, this programming language has various uses and applications, as the name suggests. Through the program, you can create various objects and classes, and even print out documents. VBA Print is just one of the commands you can use, and you can diversify it greatly to change the way you print out documents in your computer.
We will assume that you already know how to use VBA and Excel, but if you don’t you can check out the course Microsoft Excel – VBA. For those who are completely new to both Visual Basic for Applications and programming in general, try the Visual Basic for Excel Tutorial course. With over 60 discussions being held in the course and more than 8 hours of content, you can easily get into VBA programming.
VBA Macros
Of all the various features you can find in VBA, macros are one of the most useful for your work. VBA Macros are bits of compacted pieces of code that are created to be used in VBA. The main reason that macros exist is to reduce the amount of work a programmer has to do when they are writing their own code. It can save time, money, and if you know anything about programming, you know that it can save you from a great deal of headaches as well.
VBA Print has limitations on VBA when you first start out, but if you are willing to install a few macros, you can actually make the task easier. There are some macros you can use that turn the process of printing into inputting a basic command or function.
This Udemy blog Excel VBA Functions is a great post that can help you out even more when it comes to understanding and creating macros. It may not teach you everything, but it will definitely help you when it comes to understanding the basics and why they’re so important in Excel VBA.
Installing macros is easy, and using them is as simple as doing any other type of programming. If you aren’t sure about how to install macros, and you want to try adding a few to your own VBA program to make things easier on you then take this Udemy course about VBA macros.
How to Perform VBA Print for Excel
- Now that you have a basic understanding of VBA and Excel you can learn how to print using these two together. The first thing you have to do is launch Microsoft Excel and open the workbook where you want to program particular printing functions.
- The second step is to go to the Excel Options window and select Customize Ribbon. On the box next to Developer in the tabs section that’s found under Customize the Ribbon you want to make sure that it is clicked.
- Now that you’ve done this you have activated your developer tab. Close the options window and you should see the developer tab on the ribbon bar.
- Now this is the point where you will begin creating your print button through VBA. Click the Developer tab and click Insert. Select Button Control under Form Controls and then click the cell where you want the print button to be placed.
- After your button is placed you will have a window appear automatically. This is the assign macro window.
Setting Up Your Button to Print
Now that you’ve created your print button, you have to write a few basic lines of code to get it to operate. First you name your Macro into the Macro Name field, name it anything you want, but make sure that it stays relevant so you don’t get confused later. Click the new button and your VBA editor window will appear.
The VBA editor window is where you will actually see the code you will be editing and rearranging in order to get the button to perform specific tasks.
Place your cursor between two lines of code, “Sub PrintCurrentSheet ()” and “End Sub”. After you do that you will write the following line of code yourself:
ActiveSheet.PrintOut
Now all you have to do is right-click the command button and highlight the Button 1 text. Change it to something, such as “Quick Print”, and that is all there is to it. You have a button that prints instantly using VBA.
Tips and Using Other Print Function
In the tutorial above we only showed you one of the ways to print out documents, but you can change it to be more customizable if you want. For example, if you want to make it so that your button doesn’t print to the default printer that’s connected to your computer, but instead you choose the printer then you just have to write the following code in the same place where you wrote the previous line of code.
Sub QuickChangePrinter() Dim sNewPrinter As String sNewPrinter = ActivePrinter ActivePrinter = "Enter the name of the printer here" Application.PrintOut FileName:="" ActivePrinter = sNewPrinter End Sub
This tells Excel to prompt you before printing begins so you can choose the printer where you want your documents to be made.
Important Pieces of Code to Remember
When you’re using VBA Print, you want to remember some key aspects of code that you will be seeing regularly.
- ActivePrinter – This is the line of code that you may have noticed quite a bit before. This piece of code tells the program where you want to print. You can choose standard paper printers, PDF printers, or any printer that connects to your computer.
- Collate – This is an option you can use to decide if you want your work to be collated, this is not an option that you can use or need to use when you are only printing a single copy of a file.
- PrintToFile – There may be an occasion where you would prefer to print your Excel file to a file instead of onto actual printed paper. Commonly, people use this method when they want to convert an Excel file into something like a PDF file, since you would have to print your PDF file.
- IgnorePrintAreas – There may be specific print areas or points in the document that you don’t want printed out. This piece of code will help you remove those areas and print only what you want. You can also easily switch back to printing the entire worksheet and not just certain areas.
Using VBA Print for Business
Businesses all around the world use VBA Excel to help them create content and navigate quickly through Microsoft Excel and various documents. For any business professional, this tool can be easy to learn and utilize.
VBA print specifically though is a great resource, especially for those companies that handle several hundred or even thousand documents a day. Through VBA print and other forms of VBA, you could easily deal with these documents and cut out a great deal of time from your work.
The Udemy course Ultimate Excel VBA teaches business professionals about some of the key aspects of programming they will need in order to make their jobs a lot easier. The course has over 8 hours of instruction all designed to teach you how to use programming to make writing in Excel faster and more efficient.
Recommended Articles
Top courses in Excel VBA
Excel VBA students also learn
Empower your team. Lead the industry.
Get a subscription to a library of online courses and digital learning tools for your organization with Udemy Business.