Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

enabling/disabling menu items on the fly

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chip Orange - 16 Nov 2004 15:35 GMT
I have a template with a custom menu added to it.  I'd like to enable and
disable some of the menu items on the fly as the user makes various choices
(as well as when opening or creating a document).

The problem is that this evidently causes Word to think that the template
has been modified, so the users are prompted to save the template when they
exit.

Is there anything that I can do to keep Word from prompting the users about
changes to the template (obviously, I'm not talking about normal.dot here).

thanks.

Chip
Jonathan West - 16 Nov 2004 16:41 GMT
Hi Chip

Assuming that the add-in contains both the code and the menus, do the
following

Immediately before each change to the menu, add the following line of code

   Application.CustomizationContext = ThisDocument

Immediately after each change to the menu, add the following line of code.

   ThisDocument.Saved = True

This will ensure that the changes to the menus are added to your add-in and
not anywhere else, and also that they are discarded when the add-in is
unloaded.

You might also want to add the following macro as a belt-and-braces
safeguard

Sub AutoExit()
   ThisDocument.Saved = True
End Sub

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

>I have a template with a custom menu added to it.  I'd like to enable and
> disable some of the menu items on the fly as the user makes various
[quoted text clipped - 14 lines]
>
> Chip
Chip Orange - 16 Nov 2004 17:34 GMT
Thanks so much for your prompt reply Jonathan.

I had been trying to use the CustomizationContext property, but it wasn't
having any effect (that is, I would set it to the activedocument object
before making any changes to the CommandBars, and yet still receive the
prompt).

I'm not familiar with the ThisDocument object, does it represent the
template or the document being created from the template?  If it's the
latter, I wouldn't want to keep indicating that it was saved or the user
would not be prompted when they should to save their work right?

What I have done, and which seems to be working for me, is to add the line:

ActiveDocument.AttachedTemplate.Saved = True

after each modification.

Is this effectively the same as your recommendation, if not, do you see any
problems with it?

thanks.

Chip

> Hi Chip
>
[quoted text clipped - 38 lines]
> >
> > Chip
Jonathan West - 16 Nov 2004 18:00 GMT
> Thanks so much for your prompt reply Jonathan.
>
[quoted text clipped - 7 lines]
> latter, I wouldn't want to keep indicating that it was saved or the user
> would not be prompted when they should to save their work right?

It represents the file containing the code that is currently running. That
can be a document, a template or an add-in, according to circumstance.

> What I have done, and which seems to be working for me, is to add the
> line:
[quoted text clipped - 6 lines]
> any
> problems with it?

It's not necessarily the same. There are two problems with that approach.

1. You don't mention that you have set the CustomizationContext. That means
you aren't controlling where changes are getting written to. If you aren't
sure you undesratnd the CustomizationContext property, think of the Tools
Customize dialog, and the dropdown listbox that defines where customizations
are saved. That is the CustomizationContext. You have no way of knowing that
the user hasn't manually set the customization context in Tools Customize,
so you must set it yourself in code each time you make the change.

2. Using ThisDocument instead of ActiveDocument.AttachedTemplate means that
it is easier to re-use your code if you decide to do something similar as an
add-in in future.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Chip Orange - 16 Nov 2004 18:53 GMT
ok, thanks, I'll go make the change to ThisDocument.

> > Thanks so much for your prompt reply Jonathan.
> >
[quoted text clipped - 35 lines]
> it is easier to re-use your code if you decide to do something similar as an
> add-in in future.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.