Interaction between two document-level customizations opened at the same time RRS feed

  • Question

  • I have developed adocument-level customizations for Word. It has a context menu that appears in the document replacing the Word's context menu. I follow this example:

    It works fine, but when I open two documents of the same customization at the same time and I click one of the options of the context menu in one of the documents, both of the documents receive the event and perform the action at the same time.

    I have observed this behaviour only in some computers, whereas in others this interaction doesn't happen. This makes me think that some update or version of some library could fix the problem, but I still have not found the exact problem. I reproduce the problem with Office 2010 and 2007, and Windows 7 and Windows 2003.

    Any idea would be welcome...


    • Edited by mixelpl Tuesday, February 21, 2012 12:18 PM
    Tuesday, February 21, 2012 8:00 AM

All replies

  • Hi mixelpl,

    Thanks for posting in the MSDN Forum.

    Would you please explain your issue more clearly? It's based on my experience that we aren't able to open two thread for on document-level application. If you open two different document-level application, they will not affect each other.

    Have a good day,


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, February 23, 2012 5:47 AM
  • Thanks Tom for your help. I explain it better by showing the code adapted from,

    privatevoid ThisDocument_Startup(object sender, System.EventArgs e) { AddToolbar(); } privatevoid AddToolbar() { try { commandBar = Application.CommandBars["Test"]; } catch (ArgumentException e) { // Toolbar named Test does not exist so we should create it. } if (commandBar == null) { // Add a commandbar named Test. commandBar = Application.CommandBars.Add("Test", 1, missing, true); }// Add a button to the command bar and an event handler. firstButton = (Office.CommandBarButton)commandBar.Controls.Add(1, missing, missing, missing, missing); firstButton.Style = Office.MsoButtonStyle.msoButtonCaption; firstButton.Caption = "button 1"; firstButton.Tag = "button1"; firstButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(ButtonClick); commandBar.Visible = true; } } // Handles the event when a button on the new toolbar is clicked.

    privatevoid ButtonClick(Office.CommandBarButton ctrl, refbool cancel) { MessageBox.Show("You clicked: " + ctrl.Caption); }

    After installing the customization, I reproduce the problem by following these steps:

    1. Open a word template for this customization.

    2. Open a second word template for the same customization.

    3. In one of the documents I open the context menu and click "button 1"

    4. The message "You clicked..." appears twice. Once for each document.

    I have controlled the problem by including an If statement in the ButtonClick method that controls the instance that send the request by means of a propertie that I include in the parameter "ctrl", but I would like to solve it in a more elegant way.
    The problem is only reproduced in some machines, but I have not found the difference between them.

    Best regards,


    Thursday, February 23, 2012 7:50 AM