|
-
Sep 5th, 2003, 08:44 AM
#1
Thread Starter
Lively Member
CustomizationContext
I've following problem:
I have a COM AddIn for Word, developped in VB .NET. Within this AddIn some documents can be opened. To those documents the menu "Save as" (in Word) shall be disabled. For the other documents it should be enabled.
This is how I do it:
VB Code:
Dim objWord As Word.Application
objWord = CType(objWordInstance, Word.Application)
objWord.CustomizationContext = objWord.ActiveDocument
objWord.CommandBars(cstrMenuBar).Controls(cstrMenuDatei).controls(cstrMenuSaveAs).enabled = False
That's working fine.
Now I want to save and close this document. (It's saved automatically when the user closes it; therefore I'm using the DocumentBeforeClose event). During this procedure I am sometimes asked, if I want to save the document.
Just in the beginning of my DocumentBeforeClose I set the enabled-property to true again.
Any idea what may be wrong?
-
Aug 15th, 2005, 12:06 PM
#2
New Member
Re: CustomizationContext
I have had similar experience with VBA for Word 2003.
If i set the CustomizationContext property to ActiveDocument I get some unexpected behaviour:
When you close the document, the document is closed without changes being saved and with with no dialog being shown to the user.
What I found going thru Microsoft documentation, was that there was no example showing this use, the example only showed modifying the templates by setting the CustomizationContext to either NormalTemplate or ActiveDocument.AttachedTemplate.
I solved my problem by resetting the CustomizationContext to AttachedTemplate after I changed the menubar:
...
CustomizationContext = ActiveDocument
' Add Edit Button
Set myMenuBar = Application.ActiveDocument.CommandBars("Edit")
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlButton, Temporary:=True)
With newMenu
.Caption = "Menu Caption"
.Style = msoButtonCaption
.OnAction = "MenuAction" End With
CustomizationContext = ActiveDocument.AttachedTemplate ...
By resetting the CustomizationContext in the end, i don't get the unexpected behaviour.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|