When creating custom ribbons, at some points in the application I need to be able to enable and or disable the button commands.
The problem is that I can't get the ribbon to refresh before of call macro main to enable the Pause Button
Public MyRibbonUI As IRibbonUI
Public EnabledButton1 As Boolean
Public EnabledButton2 As Boolean
Public run As Boolean
Public pause As Boolean
Public Sub OnMainLoad(ribbon As IRibbonUI)
Set MyRibbonUI = ribbon
run = False
pause = False
EnabledButton1 = True
EnabledButton2 = False
End Sub
Public Sub Button_GetEnabled(control As IRibbonControl, ByRef Enabled)
Select Case control.ID
Case "Button1"
Enabled = EnabledButton1
Case "Button2"
Enabled = EnabledButton2
End Select
End Sub
Public Sub Run_OnAction(Button As IRibbonControl)
EnabledButton1 = False
EnabledButton2 = True
MyRibbonUI.InvalidateControl ("Button1")
MyRibbonUI.InvalidateControl ("Button2")
'Refreshing the ribbon interface before of call Main
If run = False And pause = False Then
run = True
Call Main
ElseIf run = True And pause = True Then
pause = False
End If
End Sub
Sub Pause_OnAction(Button As IRibbonControl)
pause = True
EnabledButton1 = True
EnabledButton2 = False
MyRibbonUI.InvalidateControl ("Button1")
MyRibbonUI.InvalidateControl ("Button2")
'Refreshing the ribbon interface
End Sub
Public Sub Main()
i = 1
Do While run
Cells(1, 1) = i
i = i + 1
DoEvents
If pause Then
Call Wait
End If
Loop
End Sub
Sub Wait()
If pause Then
Do
DoEvents
Loop Until Not pause
End If
End Sub
Bookmarks