Results 1 to 2 of 2

Thread: CustomizationContext

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    79

    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:
    1. Dim objWord As Word.Application
    2. objWord = CType(objWordInstance, Word.Application)
    3. objWord.CustomizationContext = objWord.ActiveDocument
    4. 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?

  2. #2
    New Member
    Join Date
    Aug 2005
    Location
    Rochester, New York
    Posts
    8

    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
  •  



Click Here to Expand Forum to Full Width