Home > Back-end >  Button activated on ribbon. After click, it is deactivated for two seconds and is activated again
Button activated on ribbon. After click, it is deactivated for two seconds and is activated again

Time:02-18

In the xml I have a button for the ribbon:

<button id="PRUEBA" label="Boton Prueba" size="normal" onAction="Macro11" imageMso="DirectRepliesTo"    tag="EtiquetaG" getEnabled="Habilitado"/>

For vba:

I would like this button to appear enabled to work on the ribbon, but once pressed, do the macro for which it is defined, then the button is disabled for two seconds and is enabled again. Thanks.

CodePudding user response:

In the ribbon XML you use the getEnabled callback which returns the control's state as a boolean value:

getEnabled="Habilitado"

You need to make sure it always returns a valid result depending on which your control can be disabled and enabled dynamically at runtime.

CodePudding user response:

I dont speak english, sorry. I use a translator. Well, What I intend is that when pressing the button on the ribbon, it is disabled a couple of seconds after executing the macro. The macro does nothing, it just inserts a content block of Word. Although the example I give is a test in an excel sheet, it would be for a word document. It is related to the post: Enable/Disable Ribbon Controls Independently But I would only like it to work with a button and put a timer. I do not know how to do it.

Option Explicit
Dim Rib As IRibbonUI
Public MyTag As String
'Public EnableButton1 As Boolean

Sub Habilitado(control As IRibbonControl, ByRef Enabled)
If MyTag = "Enable" Then
    Enabled = True
Else
    If control.Tag Like MyTag Then
        Enabled = True
    Else
        Enabled = False
    End If
 End If
End Sub

 Sub EnableControlsWithCertainTag3()

 'Habilita solo el control con la etiqueta Tag "SoloUno"

Call RefrescarCinta(Tag:="SoloUno")

End Sub

Sub EnabledAllControls()
'Habilita todos
Call RefrescarCinta(Tag:="*")
End Sub

Sub DisableAllControls()
'Deshabilita todos
Call RefrescarCinta(Tag:="")
End Sub

Sub RefrescarCinta(Tag As String)
MyTag = Tag
If Rib Is Nothing Then
    MsgBox "Cierra y vuelve a abrir" & vbNewLine & _
    "Visit this page for a solution: 
    http://www.rondebruin.nl/ribbonstate.htm"
  Else
    Rib.Invalidate
  End If
End Sub
Sub RibbonOnLoad(ribbon As IRibbonUI)
Set Rib = ribbon
End Sub

Lines on XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI onl oad="RibbonOnLoad" 
xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<!-- Add two custom groups on the Home Tab with a few buttons -->
<ribbon>
<tabs>
  <tab idMso="TabHome" >
    <group id="MyCustomGroup1" label="Group1" 
    tag="MyPersonalGroup1" >
      <button id="G1B1" label="Caption 1" size="normal" 
 onAction="Macro1" imageMso="DirectRepliesTo" 
    tag="SoloUno" getEnabled="Habilitado"/>         
    <button id="PRUEBA" label="Boton Prueba" size="normal" 
 onAction="Macro11" imageMso="DirectRepliesTo" 
    tag="EtiquetaG" getEnabled="Habilitado"/>
       </group>
   </tab>
</tabs>
</ribbon>
</customUI>

Macros:

Sub Macro1(control As IRibbonControl)
MsgBox "This is Macro 1 in group 1"
End Sub

Sub Macro11(control As IRibbonControl)
Application.OnTime Now   TimeValue("00:00:02"), "Macro12"
End Sub

Sub Macro12()
MsgBox "El mensaje funciona; intenta incluir en el modulo macro del 
mensaje, un timer, a ver que pasa"
End Sub
  • Related