PDA

View Full Version : Marcsters Menu controling code



gibbo1715
11-04-2005, 07:48 AM
On a previous post Marcster showed a method of running code prior to printing,

I ve been having a play and it looks like it will work for most built in word menus
thus giving the ability to prevent your user using individual menu items, thought this was real cool so thanks marcster

Thought this should be shared in its own post incase anyone missed it

This is all down to Marcsters expertise and not mine, just wanted to share it

put the code in the this document module (Works on word2000 dont know about other versions)


comments welcome

Gibbo

Sub Help()
'Overrides the F1 function key.
MsgBox "You cannot see Help."
End Sub
' Menu/Submenu
Sub FileNew()
MsgBox "opps"
End Sub
Sub FileOpen()
MsgBox "opps"
End Sub
Sub FileSave()
MsgBox "opps"
End Sub
Sub FileSaveAs()
MsgBox "opps"
End Sub
Sub ViewVBCode()
MsgBox "You cannot view the code."
End Sub
Sub EditFind()
MsgBox "Opps"
End Sub
Sub ToolsUnProtectDocument()
'Only allows unprotect from code, I think!!!
MsgBox "Opps"
End Sub
Sub Test()
ActiveDocument.Unprotect Password:="yourpassword"
End Sub

Should add that if you go to the menu at tools - macro adn type in a built in macros name (e.g. FileNew) and click create it will bring back the default value for that macro.

Marcster
11-04-2005, 08:04 AM
Thanks gibbo1715 :beerchug: ,

You can overide ANY (well I think so anyway) menu item, toolbar button, short-cut keys etc in Word.
Here's a couple more:

Sub EditSelectAll()
'Overrides Ctrl+A
MsgBox "EditSelectAll"
End Sub

Sub InsertOCXButton()
'Overide insert text button on control toolbox toolbar
MsgBox "InsertOCXButton"
End Sub


I'm trying to find the rest of them...

Previous thread here: http://www.vbaexpress.com/forum/showthread.php?t=5862

Marcster.

gibbo1715
11-04-2005, 08:22 AM
Me too

Maybe anyone who can assist can post here and we can turn it into an article as extreamly useful

Heres some more

| Sub FileNew()
End Sub
Sub FileOpen()
End Sub

Sub FileSave()
End Sub

Sub FileSaveAs()
End Sub

Sub FilePrint()
End Sub

Sub FilePrintDefault()
End Sub

Sub FilePrintPreview()
End Sub

Sub FilePrintPreviewFullScreen()
End Sub

Sub FilePrintSetup()
End Sub



Gibbo

gibbo1715
11-04-2005, 08:26 AM
Heres how you view them all

You can view a list of the built-in macros by clicking on the [Tools] menu, [Macro] and then on [Macros...]. Choose [Word commands] from the Macros in drop-down list.

It would seem you can customise any built in word macro, deleting your amended macro returns it to the default, this will work for word 95 or above as far as I can tell

How useful is that little feature!!!!!!

Thanks again to Marcster:clap:


Gibbo

Marcster
11-04-2005, 08:51 AM
Hi gibbo1715,

You've found them!. Cool. I couldn't remember how to find them.

How many do you reckon there are listed there?.
Hundreds to mess around with :devil:.

Marcster.

gibbo1715
11-04-2005, 09:44 AM
oh yes, lots of possibilites

looking forward to having a play

Gibbo

Marcster
11-04-2005, 09:59 AM
Try this...

Tested on Word 2000.

In Word, hold down CTRL+ALT and then press +
The mouse pointer changes.
Now click on a menu item or button and hey presto!. A dialog springs up which tells you what the name of the built-in macro is called!. Look in the Commands box.

Happy playing,

Marcster.

gibbo1715
11-04-2005, 11:36 AM
real cool Marcster

Gibbo

TonyJollans
11-04-2005, 11:42 AM
Hi Guys,

You can override any Word command - most via the technique you are using here but a few need a different technique. See this Microsoft Page (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnword2k2/html/odc_wdoverride.asp) for details and a sample download.

gibbo1715
11-04-2005, 03:03 PM
Thanks tony

one question, in the article it says you can overide all office applications


Although Word is the only application that provides direct support for overriding built-in menu, toolbar, and keyboard commands, you can use the CommandBar objects to override built-in menus in other Office applications. Therefore, if you are in Microsoft Excel, Microsoft Access, Microsoft PowerPoint?, or Microsoft FrontPage? and want to create a subroutine to override any of the menus, you can you use the CommandBar objects as shown above to override any (or all) of the menu items.

I ve tried putting the code in this workbook module and a normal module but wont work in excel, any ideas why?

cheers

gibbo

MOS MASTER
11-04-2005, 04:39 PM
I ve tried putting the code in this workbook module and a normal module but wont work in excel, any ideas why?


Hi Gibbo, :hi:

Like the article states Word is the only applications which uses Word commands to intercept commands. (Buttons, shortcuts, etc...)

Word is unique in that way and know other application supports this method!

However the article clearly explains how you can do the same in other applications by intercepting the buttons via the Commandbar objects.

Please try out the samples from the article and find out it works pretty much the same as using Word commands.

HTH, :whistle:

gibbo1715
11-05-2005, 01:42 AM
thanks for the reply,

I ve done the download and tried using the same method in excel 2000

tried FileSave, FileNew Open SaveAs etc..... didnt work for me:banghead:

Any chance of an attachment with a couple om so I can figure out what im doing wrong as it loks like it should be so simple

Gibbo

TonyJollans
11-05-2005, 03:55 AM
Hi gibbo,

The method of naming macros as Word command names only works in Word.

It is the other technique(s) (I can't remember off the top of my head exactly what's in the article) like setting OnAction that can be used in other applications.

Marcster
11-06-2005, 03:35 AM
I've just been searching MSDN and have come across these interesting articles:
Manipulating Command Bars and Command Bar Controls with VBA Code:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/modcore/html/deovrmanipulatingcommandbarscommandbarcontrolswithvbacode.asp
Working with Command Bar Events:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/modcore/html/deovrworkingwithcommandbarevents.asp

This is for Office 2002(XP)

Haven't read through all of it yet though...

Marcster.
Excel, how to create application level event handlers:
http://support.microsoft.com/kb/213566/

Marcster
11-08-2005, 03:10 AM
Tested in Word 2000:

Tools>Macro>Macros
Macros in: Word commands
Scroll down to ListCommands (or type ListCommands)
Run
Select All Word commands
OK

Hey presto!.
A full list of Word commands with relevent shortcut key combinations.
29 pages of them!.
1,182 commands!.

Marcster.