Menu Automation Troubles

G

Greg Maxey

I don't have a lot of experience customizing menus and toolbars
programatically and I am having fits with the following code. I call this
procedure with and AutoNew, AutoOpen macros and from several other
procedures in a larger project. The calls and code are doing what I want
them to do but for some reason everytime I run through the process and then
close Word I get a prompt that changes have been made to normal.dot and asks
if I want to save those changes.

The project and all the code are part of a template where I added a menu
("Document Bundle) to the menu bar that has three commands. I saved this
customization in the template (not the normal template).

I have used a msgbox to confirm that the customizationcontent is set to the
template containing the menu and not normal.dot. I can't figure out why
when I close Word that I get the prompt to save normal..dot.

Can anyone help? Thanks.

Sub ConfigMenu()
Dim myMenu As CommandBarControl
CustomizationContext = ActiveDocument.AttachedTemplate
'Msgbox ActiveDocument.AttachedTemplate 'Used for testing
Set myMenu = CommandBars("Menu Bar").Controls("Document Bundle")
With myMenu
If bEnableCreate Then
.Controls("Create Bundle").Enabled = True
Else
.Controls("Create Bundle").Enabled = False
End If
If bEnableUpdate Then
.Controls("Update Bundle").Enabled = True
Else
.Controls("Update Bundle").Enabled = False
End If
End With
ActiveDocument.AttachedTemplate.Save
End Sub


--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org


McCain/Palin '08 !!!
 
G

Greg Maxey

While I can't explain why, by removing the CustomizationContext line and
adding a line to declare the attached template as saved, I can run the code
without being prompted to save the attached template and close Word without
a prompt that Normal.dot has been changed. If anyone has an explanation
then please post.

Sub ConfigMenu()
Dim myMenu As CommandBarControl
'CustomizationContext = ActiveDocument.AttachedTemplate 'Suppress this
line.
Set myMenu = CommandBars("Menu Bar").Controls("Document Bundle")
With myMenu
If bEnableCreate Then
.Controls("Create Bundle").Enabled = True
Else
.Controls("Create Bundle").Enabled = False
End If
If bEnableUpdate Then
.Controls("Update Bundle").Enabled = True
Else
.Controls("Update Bundle").Enabled = False
End If
End With
ActiveDocument.AttachedTemplate.Saved = True 'Add this line.
End Sub




Greg said:
I don't have a lot of experience customizing menus and toolbars
programatically and I am having fits with the following code. I call
this procedure with and AutoNew, AutoOpen macros and from several
other procedures in a larger project. The calls and code are doing
what I want them to do but for some reason everytime I run through
the process and then close Word I get a prompt that changes have been
made to normal.dot and asks if I want to save those changes.

The project and all the code are part of a template where I added a
menu ("Document Bundle) to the menu bar that has three commands. I
saved this customization in the template (not the normal template).

I have used a msgbox to confirm that the customizationcontent is set
to the template containing the menu and not normal.dot. I can't
figure out why when I close Word that I get the prompt to save
normal..dot.
Can anyone help? Thanks.

Sub ConfigMenu()
Dim myMenu As CommandBarControl
CustomizationContext = ActiveDocument.AttachedTemplate
'Msgbox ActiveDocument.AttachedTemplate 'Used for testing
Set myMenu = CommandBars("Menu Bar").Controls("Document Bundle")
With myMenu
If bEnableCreate Then
.Controls("Create Bundle").Enabled = True
Else
.Controls("Create Bundle").Enabled = False
End If
If bEnableUpdate Then
.Controls("Update Bundle").Enabled = True
Else
.Controls("Update Bundle").Enabled = False
End If
End With
ActiveDocument.AttachedTemplate.Save
End Sub

--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org


McCain/Palin '08 !!!
 

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