ActivateTab

Dec 31, 2013 at 2:43 PM
Hi,

What is the reason that ActivateTab is not exposed via ExcelDNA IRibbonUI?
http://msdn.microsoft.com/en-us/library/office/ff861125(v=office.14).aspx

If I add code my self to:
[ComImport]
[Guid("000C03A7-0000-0000-C000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IRibbonUI

[DispId(3)]
void ActivateTab([In, MarshalAs(UnmanagedType.BStr)] string ControlID);
I get:
System.ArgumentException occurred
HResult=-2147024809
Message=Value does not fall within the expected range.
InnerException:


Alternatively:
  1. How do I activate desired ribbon tab using Excel DNA ?
  2. I need this only because after I add ListObject (Table) to collection it activates "Design" tab in ribbon, which is undesirable.
Windows 7 x64, Excel 2010 32bit

Thanks,
Arnas
Coordinator
Jan 2, 2014 at 9:27 AM
Hi Arnas,

ActiveTab is not included in the Excel-DNA copy of the interface, since it was not there in Excel 2007 when I did this.

Your plan would work, but the DispId should be 4.

The extended interface now looks like this (not sure whether you should leave the InterCall flags):
    [Guid("000C03A7-0000-0000-C000-000000000046"), TypeLibType(4160)]
    [ComImport]
    public interface IRibbonUI
    {
        [DispId(1)]
        [MethodImpl(MethodImplOptions.InternalCall)]
        void Invalidate();
        [DispId(2)]
        [MethodImpl(MethodImplOptions.InternalCall)]
        void InvalidateControl([MarshalAs(UnmanagedType.BStr)] [In] string ControlID);
        [DispId(3)]
        [MethodImpl(MethodImplOptions.InternalCall)]
        void InvalidateControlMso([MarshalAs(UnmanagedType.BStr)] [In] string ControlID);
        [DispId(4)]
        [MethodImpl(MethodImplOptions.InternalCall)]
        void ActivateTab([MarshalAs(UnmanagedType.BStr)] [In] string ControlID);
        [DispId(5)]
        [MethodImpl(MethodImplOptions.InternalCall)]
        void ActivateTabMso([MarshalAs(UnmanagedType.BStr)] [In] string ControlID);
        [DispId(6)]
        [MethodImpl(MethodImplOptions.InternalCall)]
        void ActivateTabQ([MarshalAs(UnmanagedType.BStr)] [In] string ControlID, [MarshalAs(UnmanagedType.BStr)] [In] string Namespace);
    }
Regards,
Govert
Jan 2, 2014 at 11:58 AM
Thanks. Works well.
Do you plan to add it to stable version any time soon?
Coordinator
Jan 2, 2014 at 12:07 PM
Hi Arnas,

Thanks for the feedback.

It will be updated in the next check-in.
To be clear: you need not update the interface definition in the Excel-DNA code - if you use the full interface defined in your own library and it will also work fine with the current Excel-DNA release.

-Govert
Jan 3, 2014 at 12:44 PM
Thanks for hint. Created my own copy of interface and it works fine.