How to run macro automatically before printing in Excel?
If I want to know how to run or trigger a macro automatically when print a worksheet or workbook from Excel, any good or easy method for dealing this task in Excel workbook?
Run or execute a macro automatically before printing with VBA code
Run or execute a macro automatically before printing with VBA code
Here is a simple code may help you to finish this job in Excel, please do as follows:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Then double click ThisWorkbook under the VBAProject section to open a blank module, and then copy and paste the following code into the module:
VBA code: Run macro before printing worksheet or workbook:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Call MyMacro
End Sub
Note: In the above code, please change the macro name to your need.
3. And then save and close this code window, now, after clicking Print button to print the worksheet or workbook, the specific macro will be executed firstly, after finishing the code, the worksheet or workbook will be printed at once.
Related articles:
How to run macro when cell value changes in Excel?
How to run macro based on cell value in Excel?
How to run macro based on value selected from drop down list in Excel?
How to run macro by clicking hyperlinks in Excel?
How to run macro when sheet is selected from a workbook?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!