VBA Clear Ribbon Edit Box by Button

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi, Is there a way to use a button to clear an Editbox on a Ribbon?

Code Below...

XML:
HTML:
<group id="TestTab" label="My Testing Tab">
	<checkBox id="CB1" label="Check Box Test" onAction="onActionCheck" getPressed="getPressedCheck" />
	<editBox id="FBox" label="Find" onChange="onChangeCheck" getText="getTextCheck"/>
	<button id="ClearFBox" label="Clear" onAction="ClearFString" imageMso="HappyFace" />
</group>


ThisWorkbook Module:
Code:
Public DocProps As CustomProperties
Public Property Let ribbonUI(iRib As IRibbonUI)
    Set pRibbonUI = iRib
End Property

Public Property Get ribbonUI() As IRibbonUI
    Set ribbonUI = pRibbonUI
End Property

Public Property Let CB1(b As Boolean)
    On Error Resume Next
    ThisWorkbook.CustomDocumentProperties("CB1") = b
    If Err.Number <> 0 Then
        ThisWorkbook.CustomDocumentProperties.Add Name:="CB1", LinkToContent:=False, Type:=msoPropertyTypeBoolean, Value:=b
    End If
    On Error GoTo 0
End Property

Public Property Get CB1() As Boolean
    On Error Resume Next
    CB1 = ThisWorkbook.CustomDocumentProperties("CB1").Value
    If Err.Number <> 0 Then
        CB1 = False
    End If
    On Error GoTo 0
End Property

Standard Module:
Code:
 Public oRibbon As IRibbonUI
 Public StrFind As String

Sub OnRibb******(ribbon As IRibbonUI)
    Set oRibbon = ribbon
    ThisWorkbook.ribbonUI = ribbon
    StrFind = ""
 End Sub

Function RefreshRibbon()
    If oRibbon Is Nothing Then
        'MsgBox "Error, Save/Restart your workbook"
    Else
        oRibbon.Invalidate
    End If
End Function
Sub onChangeCheck(control As IRibbonControl, ByRef text)
    StrFind = text
    oRibbon.InvalidateControl (control.ID)
End Sub
Sub getTextCheck(control As IRibbonControl, ByRef text)
    text = StrFind
End Sub
Private Sub getPressedCheck(ByVal control As IRibbonControl, ByRef returnID)
    If control.ID = "CB1" Then returnID = ThisWorkbook.CB1
End Sub
Private Sub onActionCheck(control As IRibbonControl, pressed As Boolean)
    With ThisWorkbook
        .CB1 = pressed
        .ribbonUI.InvalidateControl "CB1"
    End With
End Sub
Public Sub ClearFString(control As IRibbonControl)
    If ThisWorkbook.CB1 = True Then
                '<----------- Code to clear Edit Box
    End If
End Sub
</button></editbox></checkbox></group>
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
An example:

9KzGx8p.jpg
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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