0

I have a VSTO Excel Add-in project. I have a ribbon called "ManageTaskPaneRibbon" and on the ribbon I have a toggle button called "toggleButton1" which opens a User Control called "TaskPaneControl". When I run the addin and click on the button, the custom pane appears correctly in "Book1".

Book1 opens pane correctly from ribbon toggle button

But when I click on New Workbook, the ribbon in the new workbook "Book2" opens with the toggle button already clicked, like in "Book1".

Book1 panel closes, Book2 toggle button unchecks, Book1 toggle button remains checked

When I click on the toggle button in "Book2" the pane in "Book1" disappears, the toggle button in "Book2" is now unchecked but the togglebutton in "Book1" remains checked.

enter image description here

I based my test on this walkthrough...

Microsoft walkthrough example

In ThisAddIn, I delcared an instance of TaskPaneControl...

private TaskPaneControl taskPaneControl1;
private Microsoft.Office.Tools.CustomTaskPane taskPaneValue;

In ThisAddIn_Startup I added the TaskPaneControl to CustomTaskPanes field...

  taskPaneControl1 = new TaskPaneControl();
  taskPaneValue = this.CustomTaskPanes.Add(taskPaneControl1, "MyCustomTaskPane");
  taskPaneValue.VisibleChanged += new EventHandler(taskPaneValue_VisibleChanged);

And in the toggle button click I added the code to display the pane...

            Globals.ThisAddIn.TaskPane.Visible = ((RibbonToggleButton)sender).Checked;
            Globals.ThisAddIn.TaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionLeft;
            Globals.ThisAddIn.TaskPane.Width = 250;

I'm not sure whether I need to load a new instance of the ribbon when a new file is opened or if I need to create a new instance of the panel. Of course I am not sure how to do either. Can anyone help me figure this out?

Thanks T

TheoMysh
  • 1
  • 2

1 Answers1

0

If your source was https://learn.microsoft.com/en-us/visualstudio/vsto/how-to-add-a-custom-task-pane-to-an-application, then:

Keep in mind that the equivalent of "this" in C# is the same as "Me" in vb.net.

it might be causing you that no other interop is being activated other that the 1st instance.

shapiro yaacov
  • 2,308
  • 2
  • 26
  • 39