View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Rech Jim Rech is offline
external usenet poster
 
Posts: 2,718
Default What's special about iRibbonControl?

This is what I do, Josh:

Sub BtnOnActionCall(Ctrl As Variant)
Dim Ctrl1 As IRibbonControl
Set Ctrl1 = Ctrl
MsgBox Ctrl1.ID ''Test

Since this sub is only called when run in Excel 2007 there is no problem
declaring Ctrl1 as IRibbonControl within the sub. If you try to compile this
project in Excel 2003 (Debug, Compile) you would get an error, but there is
no reason to do this.

--
Jim
"Josh Sale" <jsale@tril dot cod wrote in message
...
I have an add-in which I'm trying to make compatible with XL2007 while
still supporting earlier versions of Excel. I've replaced my commandbars
and menus with new ribbon stuff. Each of my ribbon button's has an
onAction attribute that specifies the name of a VBA Sub in my add-in.

I'd like to code the subroutine as:

Sub ButtonClick(Control As Object)
or
Sub ButtonClick(Control As Variant)

to maintain compatibility with earlier versions of Excel which I can't do
if I code it as:

Sub ButtonClick(Control As iRibbonControl)

since iRibbonControl isn't defined in the earlier Excel libraries.

Unfortunately my approach doesn't work! When I click the button I get the
message:

run-time error 424
Object required

when my code tries to access one of the public properties of Control. If
I put Control into a Watch window, the type looks OK
("Object/iRibbonControl") and if I expand it I see the public properties
(Context, Id & Tag) but each property has a value of "<Object required".

Anybody got any explanation?

TIA,

josh

BTW, if I do code the Control argument as iRibbonControl then the rest of
my code works OK.