Adding a Menu

A

Albert

Hello!
I'd like to add a new menu after the tools and before the help menu. I would
like to do it through VBA so that when the user opens the document, the menu
appears, and when the workbook is closed, the menu disappears.
How should I go about it?
THanks,
Albert
 
J

Jezebel

Is there a particular reason you want to use VBA for this? Since the code
has to be stored somewhere -- either the document itself, or (better) the
template on which the template is based -- why not just manually add the
menu to the document or template? Then it will be shown only when the
document or template is in use, and go away of its own accord when the
document or template closes.

If you do want to do it with VBA, set the CustomizationContext (the VBA
equivalent of the 'Save In' drop-down on the Customize dialog), then use the
methods of the CommandBars collection. Note that this collection is part of
Office, not part of Word. Also make sure you have backups of your document
*and all your templates* -- there is a glitch in some versions of Word
(can't remember which ones) relating to the CustomizationContext, which
results in terminal corruption of the active template.
 
A

Albert

Hi Jezebel.
The thing is I'm making a special and highly personalized mailmerge document
for someone, and I want to have all the macros executed from a personalized
menu. Also, I want the menu to appear when they open the document, and to
disappear when they close.
That's why I want it done through vba.
Albert
 
S

Shauna Kelly

Hi Albert

May I suggest that you do the following. Perhaps even do a little dummy test
as a 'proof of concept' exercise:

1. Do File > Save As and in the "Save as type" box, choose to save as a
Template. Save it at the location identified at Tools > Options > File
Locations > User Templates.

2. Use Tools > Customize to create a new toolbar and make sure (from the
Commands tab on the Tools > Customize dialog) that you are saving the
toolbar in your template.

3. Use Tools > Customize to add buttons and menus as you need. Again, make
sure you're saving them in your template. While the Tools > Customize dialog
is open, you can right-click any button to change the text and icon.

4. Save and close.

5. Open one or two other documents, just to demonstrate.

5. Do File > New. Choose your template. You will now see that, when you swap
from one document to the other, your toolbar will appear only in the
document based on your template, and it will disappear when you view
documents based on other templates.

In Excel, you need to do all this in code. Word does it for you.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
J

Jezebel

That doesn't explain it at all. You still have to put all those macros
somewhere: put the menu in the same document or template that contains the
code.
 

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