ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to make macros work in both XL2003 and XL2010?!? (https://www.excelbanter.com/excel-programming/446816-how-make-macros-work-both-xl2003-xl2010.html)

Charlotte E.[_3_]

How to make macros work in both XL2003 and XL2010?!?
 
I'm experimenting with Ribbons in 2010, and apparrently I must create
the macro with '(Control As IRibbonControl)' to be able to call the
macro from a ribbon-button.

But this gives an a compile error in XL2003.

My quick test -macro is:

Sub Show_A1(Control As IRibbonControl)

If Range("A1").Value = "" Then
MsgBox "Cell A1 is empty!"
Else
MsgBox "Cell A1 = " & Range("A1").Value
End If

End Sub

How to make macros work in both XL2003 and XL2010 without compiler-error
in either???


CE


Living the Dream

How to make macros work in both XL2003 and XL2010?!?
 
Hi Charlotte

What about testing for the version first before the Ribbon Code is fired.

This is a snippet of code from Ron Debruin's Mail code which tests which
version is running and looks for the applicable security structure
although I think you could use it for your purpose, you will have to
change this to suit..


If Val(Application.Version) < 12 Then 'Version Running is 2000-2003
Call the applicable code.
Else
Select Case Sourcewb.FileFormat
Case 50: Call the applicable code.
Case 51: Call the applicable code.
Case 52: Call the applicable code.
Case Else: Call the applicable code.
End Select
End If

HTH
Mick.




Charlotte E.[_3_]

How to make macros work in both XL2003 and XL2010?!?
 

I knew that :-)

That's not the issue here....
....the issue is 'IRibbonControl' object which doesn't exists in
pre-ribbon versions of Excel.

unless there's a way to make a call from a ribbon to a macro without
this, it is impossible to create Excel-files with custom ribbons that
will work in both newer and older versions of Excel.

Surely Microsoft must have thought of that - question is: How???


CE


Den 10.08.2012 20:14, Living the Dream skrev:
Hi Charlotte

What about testing for the version first before the Ribbon Code is fired.

This is a snippet of code from Ron Debruin's Mail code which tests which
version is running and looks for the applicable security structure
although I think you could use it for your purpose, you will have to
change this to suit..


If Val(Application.Version) < 12 Then 'Version Running is 2000-2003
Call the applicable code.
Else
Select Case Sourcewb.FileFormat
Case 50: Call the applicable code.
Case 51: Call the applicable code.
Case 52: Call the applicable code.
Case Else: Call the applicable code.
End Select
End If

HTH
Mick.





All times are GMT +1. The time now is 04:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com