I have a VSTO application that has multiple groups and buttons on the ribbon. When a user clicks on a button a specific form is loaded on Excel. It looks like when the form is open a user is unable to open another instance of Excel unless the form is closed in the first instance. Is there a way to seperate the Add-In from different instances?
I have code developed which uses getVisbility call back to decide whether to show the tab in the ribbon based on a specific workbook. However this doesnt allow users to use multiple Excel instances whilst a windows form is open. As soon as I close the form - a new instance of excel has been opened. The VSTO Excel tool has been developed on application level.
MainRibbon.xml
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab idMso="TabAddIns" label="MDS" insertBeforeMso="TabHome" getVisible="setVisbility" >
<group id="CreateLoadModel"
label="Create/Load Model">
<button id="createmodelbutton" label="Create New Model"
screentip="Text" onAction="OnCreateModel"
supertip="Create a new Model"
imageMso="GroupSmartArtCreateGraphic"/>
<button id="loadmodelbutton" label="Load Existing Model"
screentip="Text" onAction="OnLoadModel"
supertip="Load an Exisitng Model"
imageMso="FileOpen"/>
</group>
MainRibbon.cs
public bool setVisbility(Office.IRibbonControl control)
{
int nWorkbooks = Globals.ThisAddIn.Application.Workbooks.Count;
if (nWorkbooks == 0)
{
return false;
}
if (Globals.ThisAddIn.Application.ActiveWorkbook != null && Globals.ThisAddIn.Application.ActiveWorkbook.Name == "MDS.xlsm")
{
return true;
}
else
{
return false;
}
}
AddIn.cs
private void ThisAddIn_Startup(object sender, EventArgs e)
{
this.Application.WorkbookActivate += Application_WorkbookActivate;
this.Application.WorkbookOpen += new Microsoft.Office.Interop.Excel.AppEvents_WorkbookOpenEventHandler(Application_WorkbookOpen);
}
private void Application_WorkbookActivate(Workbook Wb)
{
MainRibbon.ribbon.Invalidate();
}