Load Command bars

Mar 21, 2014 at 8:39 PM
Hi gobert,

I used Excel Dna 0.29 and Excel 2003.

I have created my Addin in C# as
public class Initializer : IExcelAddIn
{
    public void AutoOpen()
    {
        ExcelIntegration.RegisterUnhandledExceptionHandler( ex => ex.ToString() );
        //ExcelIntegration.RegisterUnhandledExceptionHandler( ErrorHandler );
        LoadCommandBars();

    }

    private object ErrorHandler(object exceptionObject)
    {
        ExcelReference caller = (ExcelReference)XlCall.Excel(XlCall.xlfCaller);
        // Calling reftext here requires all functions to be marked IsMacroType=true, which is undesirable.
        // A better plan would be to build the reference text oneself, using the RowFirst / ColumnFirst info
        // Not sure where to find the SheetName then....
        string callingName = (string)XlCall.Excel(XlCall.xlfReftext, caller, true);
        LogDisplay.WriteLine(callingName + " Error: " + exceptionObject.ToString());
        // return #VALUE into the cell anyway.
        return ExcelError.ExcelErrorValue;
    }

    public void LoadCommandBars()
    {
        ExcelCommandBarUtil.LoadCommandBars(
                @"<commandBars xmlns='http://schemas.excel-dna.net/office/2003/01/commandbars' >
                      <commandBar Name='Worksheet Menu Bar'>
                        <popup caption='Test'>
                            <popup caption='Test1'>
                                    <button caption='About Test1' onAction='InsertAboutTest1'> /button>                                        
                             </popup>                                        
                         </popup>
                      </commandBar>
                    </commandBars>");
    }

    public void AutoClose()
    {

    }
}
This code worked under Excel 2003 but do not work under Excel 2010 and ExcelDna-0.32

Do you have a same example in C# that works in Excel 2010 and ExcelDna-0.32?

Thanks
Coordinator
Mar 21, 2014 at 9:38 PM
Edited Mar 21, 2014 at 9:39 PM
Hi,

I'm not sure what would have changed to Excel-DNA 0.32 in this regard.

But you need to fix the following your code for it to work:
  • The attributes inside the tags are case sensitive. the CommandBar "name" should be in lower case:
<commandBar name='Worksheet Menu Bar'>
  • Your button tag is not properly closed </button>.
So for me it works like this:
        public void LoadCommandBars()
        {
            ExcelCommandBarUtil.LoadCommandBars(
                    @"<commandBars xmlns='http://schemas.excel-dna.net/office/2003/01/commandbars' >
                      <commandBar name='Worksheet Menu Bar'>
                        <popup caption='Test'>
                            <popup caption='Test1'>
                                    <button caption='About Test1' onAction='InsertAboutTest1'> </button>                                        
                             </popup>                                        
                         </popup>
                      </commandBar>
                    </commandBars>");
        }
-Govert
Mar 21, 2014 at 10:18 PM
thanks govet.
Yes, i have some misprints in my previous post. But the problem is that my code does not work under Excel 2010 and exceldna-0.32

Do you have a same example in C# that works in Excel 2010 and ExcelDna-0.32?
Coordinator
Mar 21, 2014 at 10:28 PM
Hi,

I have checked only under Excel 2013 (with Excel-DNA 0.32).

Are you looking under the Add-Ins tab for you command bars? Under Excel 2007+ any custom Command Bars are put under the Add-Ins tab.

-Govert
Mar 22, 2014 at 8:02 AM
Thanks Govert

Does this line is good for Excel 2010?

<commandBars xmlns='http://schemas.excel-dna.net/office/2003/01/commandbars' >
Coordinator
Mar 22, 2014 at 8:11 AM
Hi,

The xmlns is correct.

I have tested the sample in Distribution\Samples\Ribbon\CommandBars.dna under Excel 2010. Could you make a copy of the Distribution\ExcelDna.xll into the Distribution\Samples\Ribbon\ directory, rename to CommandBars.xll and open in Excel. Then there should appear an 'Add-Ins' tab on the ribbon, with some buttons under it.

Please confirm whether this works for you.

-Govert
Mar 23, 2014 at 8:04 AM
yes your example works But i do not know why my code did not work. I will test and ask you later

thanks