Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net Activating Custom Ribbon in Excel 2007 or Excel 2010 Add-in

Hi

I was given the following code to activate a custom ribbon.
I have an Excel 2007 Add-in project, but want the code to work
for Excel 2007 and Excel 2010. How do I update the code so that
it works for Excel 2007 and Excel2010



Public Class ThisAddIn
    Dim isExcel2010 As Boolean = True

    Private Sub ThisAddIn_Startup() Handles Me.Startup
        If (Version.Parse(Me.Application.Version).Major < 14) Then
            Me.isExcel2010 = False
        End If
        ActivateCustomTab(Me.Application.ActiveSheet)

    End Sub

    Private Sub ActivateCustomTab(ByVal sheet As Excel.Worksheet)
        If (Me.isExcel2010) Then
            Dim tabtoActivate As Microsoft.Office.Tools.Ribbon.RibbonTab = Nothing
            If (sheet.Name = "Sheet1") Then
                tabtoActivate = Globals.Ribbons.CustomRibbon.Tabs(0)
            ElseIf (sheet.Name = "Sheet2") Then
                tabtoActivate = Globals.Ribbons.CustomRibbon.Tabs(1)
            End If
            If (tabtoActivate IsNot Nothing) Then
                ' This method call will only work with Office 2010
                tabtoActivate.RibbonUI.ActivateTab(tabtoActivate.ControlId.ToString())
            End If

        End If
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Thanks very much