Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture the "Print" button from the menu bar in a macro

I have a sheet with a custom button on it from where I control the printing process.

Now the user clicks on the menu bar's print icon and this produces an "undefined" output.

How can I intercept this menu bar button?

  • Thanks
like image 777
Oli Avatar asked Oct 26 '25 22:10

Oli


1 Answers

Handle the Workbook_BeforePrint event.

private sub Workbook_BeforePrint (cancel as boolean)
  '//g_MyFlag is set when the user clicks you toolbar button.
  '//It must get cleared in the end of your procedure.
  if not g_MyFlag then cancel = true: exit sub

end sub

In MS Word, it's also possible to redefine the system macro itself. You'd have to create a macro named FilePrint(), and Word would call it instead its own. A pity you can't do that in Excel.

like image 157
GSerg Avatar answered Oct 28 '25 19:10

GSerg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!