Print macro query

robjowens

Board Regular
Joined
Sep 26, 2009
Messages
102
Haven't bought my copy of Walkenbach/Bible into work today and google isn't turning up anything interesting... Is there a way to insert a macro that precedes the print function so that everytime a user goes 'File -> Print' my macro does it's job and the user is none the wiser?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try in the ThisWorkbook module

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
'
'your code here
'
End Sub
 
Upvote 0
Hi

You can use the workbook's before print event. Cancel the print first, then go through all of the other configurations, and then print.

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Cancel = True
    'rest of macro
End Sub
 
Upvote 0
Thanks Jon & VoG,

Jon, by using your method the sheet comes up with a message saying there's nothing to print. Do I have to turn on the print function once my macro has been inserted?

thanks,
Rob
 
Upvote 0
Can you share with us the rest of the macro? It might not be necessary to cancel the print first. I tend to cancel, then do the configurations (.e.g page setup) and then I tell it to print at the end, usually using the PrintOut method.
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,774
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top