PDA

View Full Version : Solved: Menu Item



RECrerar
10-05-2007, 05:27 AM
Is it possible to create a new menu item in say the 'Tools' menu in Word?

i have been having a look though the posts and on google have so far only found information on adding new toolbar items and a whole new menu item.

What I would ideally like it just to be able to add a new option in the tools menu. I can do this in excel but am becoming acutely aware that word is not like Excel in many ways.

RECrerar
10-05-2007, 06:29 AM
I found the follwing link via google, which is very helpful and have managed to create the menu item:

http://www.vbforums.com/showthread.php?t=402042

The code below adds a new item to the tools menu and assigns a macro to that item.

Option Explicit
'<CREATE THE EVENT HANDLER>
Public WithEvents oCBBCustom As Office.CommandBarButton
Dim oCB As Office.CommandBar
Dim oCBBTools As Office.CommandBarPopup


Private Sub Document_Open()
'<DRILL DOWN THE COMMANDBAR OBJECT HEIRARCHY>
Set oCB = Application.CommandBars("Menu Bar")
Set oCBBTools = oCB.Controls("&Tools")
'<ADD A NEW BUTTON>
Set oCBBCustom = oCBBTools.Controls.Add(msoControlButton, 1, , , True)
'Place our custom one at the bottom
With oCBBCustom
.Caption = "Convert to .txt..."
.BeginGroup = True
.OnAction = "WordDocOpen"
.Enabled = True
.Visible = True
End With
End Sub



Private Sub Document_Close()
Set oCB = Application.CommandBars("Menu Bar")
Set oCBBTools = oCB.Controls("&Tools")
oCB.Reset
End Sub

crowfan
10-05-2007, 08:05 AM
If I am reading your OP right, there is a very easy way to do this.

Create your macro. Then go back into Word and click View > Toolbars > Customize. On the Commands tab, select the Macros category, then click an drag your macro up to the Tools menu. Don't release the mouse button. The menu should open. Then just drag the macro down to the desired location and release the mouse button. You can then right click the macro name to edit it and make it user-friendly.

Apologies if I misinterpreted your OP and this post is useless. :)

RECrerar
10-08-2007, 01:15 AM
Hey,

Interpreted correctly. That is a vaey nice and simple way to do it. Would that work though automatically if the program is saved as a .dot file that a numebr of users need to save to their start up file? I would like the macro to be automatically added to the Tools menu without the users having to assign it themselves the first time they use the program.

fumei
10-08-2007, 01:33 AM
Once you do it to a file - whether .doc OR .dot - that customization persists. Templates (.dot) will clone documents with the same customization. In other words, if it is a new item on Tools, in the .dot file, any .doc file clones with also have it.

Again, that is one of the reasons for .dot (template) files. Which is why you should NOT be doing this in in your file currently going on in your other thread.

RECrerar
10-08-2007, 01:44 AM
Thanks for that information, I shall remember that. In the interest of not having to change stuff now I have done it, is there a problem with adding the menu item using the code I used? I can see that for future use the Tools, Customise method is simpler and probably neater but if there isn't a real disadvantage of using the code I would rather not have to change what I've done.


Again, that is one of the reasons for .dot (template) files. Which is why you should NOT be doing this in in your file currently going on in your other thread.

I don't quite understand what you are talking about here, which bit should I not be doing? From my end, my program which I have saved as a .dot after I finished writing it seems to work on my computer and on another computer where I tested it. I have a couple of other threads going on, so am wondering which one you are refering to.

fumei
10-08-2007, 01:57 AM
I looked at your convert doc to txt file.

It is a DOC file. It should not be a doc file. This should be a procedure in a global template.

I think it is strange that you create a separate folder for each file. Odd. But whatever.

My point is that if this was a procedure in a global template, the "Convert to text" item would be in your Tools menu, with no need AT ALL to run code to add commandbars yadda yadda yadda.

Why run code when you don't have to? Shrug, I guess a different way of looking at things. If I don't have to run code....I don't. And you don't have to run that code at all.

You can have the procedure to convert any given file.

RECrerar
10-08-2007, 02:20 AM
Oh I see where you are coming from now, the .doc file uploaded is now out of date. I listened to the advice that this was not the correct form and have it now saved as a .dot in the global template, just have not changed the version uploaded onto the site.

I create a seperate folder for the files as with the main part of the program (in Excel), a .xls file and some FEMAP (an finite element analysis program) files will also be added to these folders, so creating the new folder just keeps the work neater.

I can see the advantage of not writing the code, I just didn't know how to do it without writing code before. Have just tried the view, toolbars, customise method and deleted the code

lucas
10-08-2007, 07:37 AM
I can do this in excel but am becoming acutely aware that word is not like Excel in many ways.

That's all I'm sayin'

fumei
10-08-2007, 07:53 PM
See signature line.