Menu commands - overruling with macro - How to do it?

J

Jan Kronsell

If I make a procedure like this in word:

Sub FilePrint()
MsgBox "hello"
End Sub

it will overule the normal File - Print menu command and the same goes for
alle the menu commands.

How do I accomplish the same in Excel. I tried with the above code in a
module, ThisWorkbook module and in a Sheet module.

am I doing someting wrong, or does it simply not work in Excel.

Jan
 
B

Bernie Deitrick

Jan,

In the codemodule of the ThisWorkbook object:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
FilePrint
End Sub

Put your FilePrint code into a standard module in the same workbook.

HTH,
Bernie
MS Excel MVP
 
J

Jan Kronsell

I know how to use events, that will only work if a suiting wevent exist. The
FilePrint was just an example. It migh as well have been FormatColumn or
InsertRow or any other built in commands.

I also know I can edit the menu item so it plays a macro, whwen selected,
but that will not prevent user from accessing the original function by using
a shortcut.

What I really need is to make my own function for fx saving a file, and make
that the only way to save a file (in a specific workbook).

Jan
 
B

Bernie Deitrick

Jan,
What I really need is to make my own function for fx saving a file, and make
that the only way to save a file (in a specific workbook).

As in my example, use the Workbook's BeforePrint event for this, in
the specific workbook.

Other than that, you can try to intercept all the commands and
override all the shortcuts, but you'll have a bunch of angry users.
Search the Google groups to find examples - none are foolproof.

HTH,
Bernie
MS Excel MVP
 
J

Jan Kronsell

Thanks. I'll look into it.

Jan

Bernie Deitrick said:
Jan,


As in my example, use the Workbook's BeforePrint event for this, in
the specific workbook.

Other than that, you can try to intercept all the commands and
override all the shortcuts, but you'll have a bunch of angry users.
Search the Google groups to find examples - none are foolproof.

HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top