Refreshing the ribbon interface before a call from a macro

ElmerCC

New Member
Joined
Jan 19, 2021
Messages
1
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
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:
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>
The problem is that I can't get the ribbon to refresh before of call macro main to enable the Pause Button

1611069901432.png

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
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top