Results 1 to 4 of 4

Thread: [RESOLVED] Customizing the Ribbon - Excel

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [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?

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Customizing the Ribbon - Excel

    Not sure if this link helps...

    http://blogs.msdn.com/b/vsto/archive...eflection.aspx

    Sid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    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>

  4. #4

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    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">

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width