When creating custom ribbons, at some points in the application I need to be able to enable and or disable the button commands.
Here is the specific portion of the ribbon script:
The problem is that I can't get the ribbon to refresh before of call macro main to enable the Pause Button
Here is the specific portion of the ribbon script:
VBA Code:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnMainLoad">
<ribbon startFromScratch="false">
<tabs>
<tab id="CustomTab" label="Refresh-Ribbon">
<group id="Group1" label="Problema">
<button id="Button1"
label="Run"
imageMso="RecordingPlay"
size="large"
onAction="Run_OnAction"
getEnabled="Button_GetEnabled"/>
<button id="Button2"
label="Pause"
imageMso="PauseSharedSpace"
size="large"
onAction="Pause_OnAction"
getEnabled="Button_GetEnabled"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
VBA Code:
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