Solved Activating Custom Ribbon in Excel 2007 or Excel 2010 Add-in

Posted on 2012-09-20
Last Modified: 2012-09-22

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

    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
            End If

        End If
    End Sub
Question by:murbro
    LVL 85

    Accepted Solution

    There is no equivalent for 2007 in the object model so I suspect you need Sendkeys or to use IAccessibility - check out Tony Jollans' page here:

    It's for VBA but perhaps you can translate to .Net (I can't!)

    Author Closing Comment

    Thanks very much

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
    This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now