how can I disable a control in the ribbon at run time

  • Follow


As an example, in Excel 2007, I have 5 buttons on the ribbon. When I press a 
button, it runs code and then it is meant to disable the button. Do you know 
how I could do this? Any help would be appreciated.
0
Reply Utf 1/15/2010 11:16:07 PM

Hi irvy

See
http://www.rondebruin.nl/hidevisible.htm

-- 

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"irvy" <irvy@discussions.microsoft.com> wrote in message news:263AA8E7-98F0-4999-BC5B-E249253013AB@microsoft.com...
> As an example, in Excel 2007, I have 5 buttons on the ribbon. When I press a 
> button, it runs code and then it is meant to disable the button. Do you know 
> how I could do this? Any help would be appreciated.
0
Reply Ron 1/15/2010 11:28:39 PM


Hey Ron,
Thanks for the quick reply. I have checked out your examples. What
they do is actually make the controls invisible. I still want to see
the control but want it disabled. Is that possible?

irvy
0
Reply Irvy 1/19/2010 6:40:34 AM

Hi Ron,

I am still having some problems. I am just testing out the process
before I proceed with my actual code but I am getting this error:

"Runtime 91. Object variable or With block variable not set"

Can you tell me why I am getting this error?

Here is my xml code:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI onLoad="RibbonOnLoad" xmlns="http://schemas.microsoft.com/
office/2006/01/customui">
  <ribbon>
    <tabs>

      <tab idMso="TabHome" >

        <group id="grp1" label="Group1" tag="MyPersonalGroup" >
          <button id="btn1" label="button1" size="large"
onAction="disableBtn1" getEnabled="GetEnabled"
imageMso="DirectRepliesTo" />
          <button id="btn2" label="button2" size="large"
onAction="disableBtn2" getEnabled="GetEnabled" imageMso="AccountMenu" /
>
    	  </group>

	</tab>

    </tabs>
  </ribbon>
</customUI>

and here is my vba code:

Option Explicit
Dim Rib As IRibbonUI

'Callback for customUI.onLoad
Sub RibbonOnLoad(ribbon As IRibbonUI)
    Set Rib = ribbon
End Sub

'Callback for btn1 getEnabled
Sub GetEnabled(control As IRibbonControl, ByRef returnedVal)
    returnedVal = True
End Sub

'Callback for btn1 onAction
Sub disableBtn1(control As IRibbonControl)
    Dim Rib As IRibbonUI
    Rib.InvalidateControl ("btn1")
End Sub

'Callback for btn2 onAction
Sub disableBtn2(control As IRibbonControl)
    Dim Rib As IRibbonUI
    Rib.InvalidateControl ("btn2")
End Sub
0
Reply Irvy 1/22/2010 8:48:45 AM

3 Replies
1101 Views

(page loaded in 0.104 seconds)

Similiar Articles:
















7/19/2012 7:53:39 PM


Reply: