[RESOLVED] Customizing the Ribbon - Excel
I have a VSTO application and I customize the ribbon to add my own buttons using the code below.
Code:
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new ReportsRibbon();
}
I also have a button which opens a new workbook (without the custom ribbon).
My problem is that when the new workbook is opened the original one also loses the sustomised ribbon items, is there a way to prevent or handle this?
Re: Customizing the Ribbon - Excel
Re: Customizing the Ribbon - Excel
I google searched and found this guy had the same problem as I have but I cant make sense of his solution.
http://social.msdn.microsoft.com/For...3-b94c673fc0dd
My code is as below
protected override Microsoft.Office.Core.IRibbonExtensibility
Code:
CreateRibbonExtensibilityObject()
{
return new ReportsRibbon();
}
Code:
{
[ComVisible(true)]
public class ReportsRibbon : Office.IRibbonExtensibility
{
private Office.IRibbonUI ribbon;
public ReportsRibbon()
{
}
#region IRibbonExtensibility Members
public string GetCustomUI(string ribbonID)
{
return GetResourceText("Corp.ExcelReports.IT.CRSUsageReport.ReportsRibbon.xml");
}
#endregion
#region Ribbon Callbacks
//Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{
this.ribbon = ribbonUI;
}
public void ShowFactors(Office.IRibbonControl control)
{
Globals.ThisWorkbook.objfrmFactors.ShowDialog();
}
#endregion
#region Helpers
private static string GetResourceText(string resourceName)
{
Assembly asm = Assembly.GetExecutingAssembly();
string[] resourceNames = asm.GetManifestResourceNames();
for (int i = 0; i < resourceNames.Length; ++i)
{
if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
{
using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
{
if (resourceReader != null)
{
return resourceReader.ReadToEnd();
}
}
}
}
return null;
}
HTML Code:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab idMso="TabAddIns" label="Corp">
<group id="gFactors"
label="Factors">
<button id="btnShowFactors" label="Show Factors"
screentip="Show Factors" onAction="ShowFactors"
supertip="Displays the Factors Action Panel."
imageMso="ViewDocumentActionsPane" size="large" />
</group>
<group id="gZoom"
label="Zoom">
<button id="btnZoom" label="Zoom"
screentip="Show Factors" onAction="Zoom"
supertip="Zooms selected data."
imageMso="ViewDocumentActionsPane" size="large" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Re: Customizing the Ribbon - Excel
Resolved by changing
Code:
<tabs>
<tab idMso="TabAddIns" label="Corp">
<group id="gFactors"
label="Factors">
to
Code:
<tab idMso="TabAddIns" label="Corp" visible="false" />
<tab id="dbCustomTab" label="Corp" visible="true">