Murray Brown
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.Applicat ion.Versio n).Major < 14) Then
Me.isExcel2010 = False
End If
ActivateCustomTab(Me.Appli cation.Act iveSheet)
End Sub
Private Sub ActivateCustomTab(ByVal sheet As Excel.Worksheet)
If (Me.isExcel2010) Then
Dim tabtoActivate As Microsoft.Office.Tools.Rib bon.Ribbon Tab = Nothing
If (sheet.Name = "Sheet1") Then
tabtoActivate = Globals.Ribbons.CustomRibb on.Tabs(0)
ElseIf (sheet.Name = "Sheet2") Then
tabtoActivate = Globals.Ribbons.CustomRibb on.Tabs(1)
End If
If (tabtoActivate IsNot Nothing) Then
' This method call will only work with Office 2010
tabtoActivate.RibbonUI.Act ivateTab(t abtoActiva te.Control Id.ToStrin g())
End If
End If
End Sub
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.Applicat
Me.isExcel2010 = False
End If
ActivateCustomTab(Me.Appli
End Sub
Private Sub ActivateCustomTab(ByVal sheet As Excel.Worksheet)
If (Me.isExcel2010) Then
Dim tabtoActivate As Microsoft.Office.Tools.Rib
If (sheet.Name = "Sheet1") Then
tabtoActivate = Globals.Ribbons.CustomRibb
ElseIf (sheet.Name = "Sheet2") Then
tabtoActivate = Globals.Ribbons.CustomRibb
End If
If (tabtoActivate IsNot Nothing) Then
' This method call will only work with Office 2010
tabtoActivate.RibbonUI.Act
End If
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER