How to capture the print button from a menu bar in a macro

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

Now the user clicks on the print icon on the menu bar, and this leads to the output of "undefined".

How to intercept this button on the menu bar?

  • thank
+3
source share
1 answer

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, you can also override the system macro itself. You will need to create a macro with a name FilePrint(), and Word will be its own instead. Too bad you can't do this in Excel.

+3
source

Source: https://habr.com/ru/post/1697708/


All Articles