• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2194
  • Last Modified:

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


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
Murray Brown
Murray Brown
1 Solution
Rory ArchibaldCommented:
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: http://www.wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.php

It's for VBA but perhaps you can translate to .Net (I can't!)
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now