'Enable/Disable Ribbon Controls Independently
I've been searching many times for a solution to this and the closest solution is Ron de Bruin example but it does not cover what I need.
I am trying to do is essentially 2 things
Example: I have 4 buttons.
Button1 on Group1 and tab1
Button2 on Group1 and tab1
Button3 on Group2 and tab2
Button4 on Group2 and tab2
When the ribbon control "Button1" is clicked it will run some code and disable the "Button1" at the end.
When the ribbon control "Button2" is clicked it will run some code and the check the "Button3" and "button4" and set the opposite properties.
If button3 was true, it becomes false.
If button4 was false, it becomes true.
Can you provide some guidance to solve this
Solution 1:[1]
Explantion provided by Commonsense help me to build that final solution for the revised question asked. Thanks
Option Explicit
Public MyRibbonUI As IRibbonUI
Public EnableButton1 As Boolean
Public EnableButton2 As Boolean
Public EnableButton3 As Boolean
Public EnableButton4 As Boolean
Public Sub OnRib_Load(ribbon As IRibbonUI)
'
' Code for onLoad callback. Ribbon control customUI
'
Set MyRibbonUI = ribbon
EnableButton1 = True
EnableButton2 = True
EnableButton3 = True
EnableButton4 = False
End Sub
Public Sub Button_GetEnabled(control As IRibbonControl, ByRef Enabled)
'
' Code for getEnabled callback. Ribbon control button
'
Select Case control.ID
Case "Button1"
Enabled = EnableButton1
Case "Button2"
Enabled = EnableButton2
Case "Button3"
Enabled = EnableButton3
Case "Button4"
Enabled = EnableButton4
End Select
End Sub
Public Sub Button1_onAction(control As IRibbonControl)
'
' Code for onAction callback. Ribbon control button
'
EnableButton1 = False
MyRibbonUI.InvalidateControl ("Button1")
End Sub
Public Sub Button2_onAction(control As IRibbonControl)
'
' Code for onAction callback. Ribbon control button
'
If EnableButton3 = False Then
EnableButton3 = True
Else
EnableButton3 = False
End If
MyRibbonUI.InvalidateControl ("Button3")
If EnableButton4 = False Then
EnableButton4 = True
Else
EnableButton4 = False
End If
MyRibbonUI.InvalidateControl ("Button4")
End Sub
Public Sub Button3_onAction(control As IRibbonControl)
'
' Code for onAction callback. Ribbon control button
'
End Sub
Public Sub Button4_onAction(control As IRibbonControl)
'
' Code for onAction callback. Ribbon control button
'
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
