I have moved a couple of ribbon callback routines (that worked previously) into a conditional compile block so that I don't get compile errors when I work in Excel 2003. Compiling works fine now in Excel 2003 but when I run my program in Excel 2007 it doesn't seem to find the routines and thus throws the error "Cannot run the macro 'Ribbon_Loaded'. The macro may not be available in this workbook or all macros may be disabled."
Macros are certainly enabled. I am running this in Windows XP SP3 and Excel 2007 SP2.
Here is the code that I'm using as the conditional compile:
The code for the ExcelVersion function used above is:
I wonder if there is some problem with using a user defined function as the condition for compilation. If so is there any built in function that would bring back a value to help me distinguish between excel versions that use the ribbon and ones that don't?
Thank you for whatever time you spend considering this problem,
Derrick
Macros are certainly enabled. I am running this in Windows XP SP3 and Excel 2007 SP2.
Here is the code that I'm using as the conditional compile:
Code:
#If ExcelVersion >= 12 Then
Dim Rib As IRibbonUI
'Callback for customUI.******
Sub ribbon_Loaded(ribbon As IRibbonUI)
Set Rib = ribbon
End Sub
'Callback for OfficeMenu buttons when they are clicked (onAction event)
Sub OfficeButton_Click(control As IRibbonControl)
Select Case control.ID
Case "customFileNew"
AccessNewTest
Case "customFileOpen"
AccessOpenTest
Case "customFileSave"
AccessSaveTest
End Select
End Sub
#End If
Code:
Public Function ExcelVersion() As Integer
Dim varVersion As String
varVersion = Application.version
'strip off any text etc. return number only
ExcelVersion = CInt(Left(varVersion, InStr(1, varVersion, ".") - 1))
End Function
Thank you for whatever time you spend considering this problem,
Derrick