none
In a VSTO MS Word add-in, a Ribbon Toggle button clicked in one document causes it to be clicked in other running instances of MS Word RRS feed

  • Question

  • I have developed a MS Word add-in and it has several buttons in the ribbon menu. The first button is a Toggle button and clicking it causes a task pane to load. The problem I have been experiencing is that if I have multiple instances of MS Word open and I click this toggle button in one of the instances, it automatically appears clicked in the other running instances of MS Word as well but the task pane appears to be loaded only in the instance where I had clicked the toggle button. I would like the toggle button to work independently in every instance of MS Word. I have tried several ways of doing this but haven't found a solution yet. I have experienced the same behavior for another add-in that I developed for MS PowerPoint.

    Any help in this matter will be appreciated.

    Monday, October 12, 2015 4:23 AM

Answers

  • Hi RoJoshi,

    As far as I know, this is by design, for an instance with multiple word documents, the same add-in will be in a domain, for example, a variable is changed will be affect other word documents if they are in the same instance. So, you need to deal with this scenario. (e.g. base on document name)

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, October 14, 2015 5:55 AM
    Moderator

All replies

  • Have you handled the event 

     void wdEventsX_DocumentChange()
            {

            }

    Monday, October 12, 2015 10:08 AM
  • No but I tried with NewDocument and DocumentOpen events unsuccessfully. Can you please elaborate more on the usage of DocumentChange event?
    Monday, October 12, 2015 10:15 AM
  • Hi RoJoshi,

    Please provide the detail code and detail steps.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 13, 2015 6:59 AM
    Moderator
  • I have a ribbon designer (named rbcOfficeAddin) added to my add-in project and it has a toggle button named btnTaskPane. Below is the code:

    public partial class rbcOfficeAddin
    {
    	private void btnTaskPane_Click(object sender, RibbonControlEventArgs e)
    	{
    		if (this.btnTaskPane.Checked)
    		{ this.btnTaskPane.Label = "Hide Task Pane"; }
    		else { this.btnTaskPane.Label = "Show Hide Pane"; }
    		Globals.ThisAddIn.ShowHideActionPane(this.btnTaskPane.Checked);
    	}
    }


    The click handler of toggle button calls a method of ThisAddin as shown below:

    public partial class ThisAddIn
    {
    	private bool operationsPaneCreated = false;
    
    	public void ShowHideActionPane(bool flag)
    	{
    		try
    		{
    			if (!this.operationsPaneCreated)
    			{
    				this.CreateTaskPane();
    				this.operationsPaneCreated = true;
    			}
    			myCustomTaskPane.Visible = flag;
    		}
    		catch (Exception ex)
    		{
    			MessageBox.Show(ex.Message);
    		}
    	}
    
    	private void CreateTaskPane()
    	{
    		//OperationsPane is a user control
    		oOperationsPane = new OperationsPane();
    		myCustomTaskPane = this.CustomTaskPanes.Add(oOperationsPane,
    			"Operations Pane");
    
    		myCustomTaskPane.DockPosition =
    			Office.MsoCTPDockPosition.msoCTPDockPositionFloating;
    		myCustomTaskPane.Height = 500;
    		myCustomTaskPane.Width = oOperationsPane.Width;
    
    		myCustomTaskPane.DockPosition =
    			Office.MsoCTPDockPosition.msoCTPDockPositionRight;
    		myCustomTaskPane.Width = 420;
    		myCustomTaskPane.Control.AutoScroll = true;
    
    		myCustomTaskPane.Visible = false;
    
    		myCustomTaskPane.VisibleChanged += myCustomTaskPane_VisibleChanged;
    	}
    
    	void myCustomTaskPane_VisibleChanged(object sender, EventArgs e)
    	{
    		try
    		{
    			if (!myCustomTaskPane.Visible && Globals.Ribbons.rbcOfficeAddin.btnTaskPane.Checked)
    			{
    				Globals.Ribbons.rbcOfficeAddin.btnTaskPane.Checked = false;
    				Globals.Ribbons.rbcOfficeAddin.btnTaskPane.Label = "Show Task Pane";
    			}
    		}
    		catch (Exception ex)
    		{
    			MessageBox.Show(ex.Message);
    		}
    	}
    }
    Steps:

    1. Now when I run the code, I see the toggle button in the ribbon as expected.

    2. On clicking the toggle button, the Task Pane shows up as expected.

    3. At this point I open a new MS Word document and navigate to my custom ribbon item.

    4. Here I notice that the toggle button appears in checked state. Checking and un-checking the toggle button does no action in this newly opened document. It hides/unhides the Task Pane in the original document where the Task Pane was initially loaded in step 1.

    • Edited by RoJoshi Tuesday, October 13, 2015 10:35 AM Added steps
    Tuesday, October 13, 2015 10:17 AM
  • Hi RoJoshi,

    As far as I know, this is by design, for an instance with multiple word documents, the same add-in will be in a domain, for example, a variable is changed will be affect other word documents if they are in the same instance. So, you need to deal with this scenario. (e.g. base on document name)

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, October 14, 2015 5:55 AM
    Moderator
  • That's disappointing. I will have to think of some logic to make it work when multiple instances of Word are open but it's not going to be pretty.

    Thanks Starain for all your help.

    Monday, October 19, 2015 11:33 AM
  • Hi RoJoshi

    The following article explains the approach. It's valid for Ribbon customizations as well as just Custom Task Panes

    https://msdn.microsoft.com/en-us/library/vstudio/bb608620


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Monday, October 19, 2015 1:10 PM
    Moderator
  • Thanks Cindy, I will try to apply it.
    Tuesday, October 20, 2015 10:34 AM