creating custom menus

J

Jan Kucera

Hi,
how can I create a custom menu in Word (2003) without explicitly installing
add-in? I mean can it be done in VBA or VSTO?

Thanks, Jan
 
D

Dawn Crosier

Here is some code that I keep in my code library. Dian Chapman shared
it with me. It should shed some light on the various options available
to you.

Sub BuildCustomMenus()

'build graphic menus on the fly

'less chance of errors, by Dian Chapman



Dim vCtrlCount As Integer

Dim ctrlControl As CommandBarControl



'delete any previously created custom toolbars and rebuild

With Application.CommandBars("Menu Bar")

.Controls("GraphicCues").Delete

.Controls("GuideOptions").Delete

End With



'create the custom 'graphic' and 'option' command bar.

vCtrlCount = CommandBars("Menu Bar").Controls.Count

vCtrlCount = vCtrlCount + 1

With CommandBars("Menu Bar").Controls

.Add(Type:=msoControlPopup, Before:=vCtrlCount) _

.Caption = "&GuideOptions"

.Add(Type:=msoControlPopup, Before:=vCtrlCount + 1) _

.Caption = "&GraphicCues"

End With



'add more macros to options here...and create

'sub...add to select case statement

'1. Add the buttons

'2. title caption

'3. Display only the caption text

'4. call procedure to pass button call



Set ctrlControl = CommandBars("Menu Bar") _

.Controls("GuideOptions").Controls.Add(msoControlButton)

ctrlControl.Caption = "Build a &Module/Program"

ctrlControl.Style = msoButtonCaption

ctrlControl.OnAction = "BuildModuleDoc"



Set ctrlControl = CommandBars("Menu Bar") _

.Controls("GuideOptions").Controls.Add(msoControlButton)

ctrlControl.Caption = "Build &Daily Overview"

ctrlControl.Style = msoButtonCaption

ctrlControl.OnAction = "BuildDailyOverview"



Set ctrlControl = CommandBars("Menu Bar") _

.Controls("GuideOptions").Controls.Add(msoControlButton)

ctrlControl.Caption = "Build A &Lesson"

ctrlControl.Style = msoButtonCaption

ctrlControl.OnAction = "BuildLessonSection"



Set ctrlControl = CommandBars("Menu Bar") _

.Controls("GuideOptions").Controls.Add(msoControlButton)

ctrlControl.Caption = "Insert &Slide (wmf)"

ctrlControl.Style = msoButtonCaption

ctrlControl.OnAction = "InsertSlide"



Set ctrlControl = CommandBars("Menu Bar") _

.Controls("GuideOptions").Controls.Add(msoControlButton)

ctrlControl.Caption = "Insert &Table of Contents"

ctrlControl.Style = msoButtonCaption

ctrlControl.OnAction = "InsertToc"

End Sub




--
Dawn Crosier
Microsoft MVP
"Education Lasts a Lifetime"

This message is posted to a newsgroup. Please post replies and
questions to the newsgroup so that others can learn as well.
 
J

Jan Kucera

Thanks Dawn, this helped. ;-)

I have a problem. I perform the menu cleanup during document's close event,
however the menus are explicitly saved with the document.

How can I avoid this?

Jan.
 
D

Dawn Crosier, MVP

Jan -

Would you post the code that you are using in the document_close event? My
thought is that you have saved the document, you delete the commands, but
you don't re-save the changes.

Dawn Crosier
Microsoft MVP
"Education Lasts a Lifetime"

This message is posted to a newsgroup. Please post replies and questions to
the newsgroup so that others can learn as well.
 
J

Jan Kucera

Hi Dawn,
I just use CommandBars("MyMenu").Delete that's all what I have in the
document_close.
However as I read through your post, I've got an idea, to call Save after
deleting the menu (and perhaps setting Saved to true). Will that work?

The problem which will remain is when the user press save button. Then the
menu will be saved... no workaround for this?

Thanks for help,
Jan.
 
D

Dawn Crosier, MVP

Jan -

Are you creating the menu with the Document_New event or the Document_Open?
As I was typing a response regarding the Save event, it occured to me that
if you save the doucment after removing the menu's that potentially you
could be saving changes that the user did not intend to save. They made
changes and rather than pressing the Undo button, they chose to close the
document and not save the changes.

--
Dawn Crosier
Microsoft MVP
"Education Lasts a Lifetime"

This message was posted to a newsgroup, Please post replies and questions
to the group so that others can learn as well.
 
G

G.L.

use this to clear any built-in bar:

if Me.CommandBars("Name").Buidin=True then
Me.CommandBars("Name").Reset
end if
 

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