Skip to main content

editBox Element

The editBox element specifies an edit box control that allows a user to enter a string of text.

Graphical View of editBox Attributes

The following figure shows all the visible graphical attributes you can set on the editBox control.

This is specified using the following XML:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
	<!-- true: show only your tab in Excel -->
	<ribbon startFromScratch="true">
		<tabs>
			<tab id="customTab"
			     label="Custom Tab">
				<group id="customGroup"
				       label="Custom Group">
					<editBox id="rxtxtRename1"
					         label="editBox Demo 1"
					         enabled="false"
					         imageMso="SignatureLineInsert"
					         keytip="E1"
					         screentip="screentip 1"
					         supertip="supertip 1"
					         maxLength="4"
					         sizeString="0123456789"
					         onChange="editBox1_Change"/>
					<editBox id="rxtxtRename2"
					         label="editBox Demo 2"
					         image="custom-icon"
					         keytip="E2"
					         screentip="screentip 2"
					         supertip="supertip 2"
					         maxLength="8"
					         sizeString="0123456789ABCDEFGHIJ"
					         onChange="editBox2_Change"/>
				</group>
			</tab>
		</tabs>
	</ribbon>
</customUI>

Note: image="custom-icon": you need to create a custom icon yourself.

Parent Elements

Children Elements

The editBox control does not support child objects of any kind.

Required Attributes

The ididQ, and idMso attributes are mutually exclusive. At least one of these attributes MUST be specified.

ATTRIBUTE WHEN TO USE
id Create your own editBox
idMso Use an existing built-in editBox
idQ Create an editBox shared between namespaces

Required Callback

DYNAMIC ATTRIBUTE ALLOWED VALUES VBA CALLBACK SIGNATURE
onChange 1 to 4096 characters Sub OnChange (control As IRibbonControl, text As String)

Optional insert Attributes

The insertAfterMsoinsertAfterQinsertBeforeMso, and insertBeforeQ attributes are mutually exclusive. If none of these attributes are specified, the controls SHOULD be appended to the existing set of controls, in the order they are defined in the XML.

INSERT ATTRIBUTE ALLOWED VALUES DEFAULT VALUE WHEN TO USE
insertAfterMso Valid Mso Group Insert at end of group Insert after built-in control
insertBeforeMso Valid Mso Group Insert at end of group Insert before built-in control
insertAfterQ Valid Group idQ Insert at end of group Insert after shared namespace control
insertBeforeQ Valid Group idQ Insert at end of group Insert before shared namespace control

Optional Attributes and Callbacks

STATIC ATTRIBUTE DYNAMIC ATTRIBUTE ALLOWED VALUES DEFAULT VALUE VBA CALLBACK SIGNATURE FOR DYNAMIC ATTRIBUTE
enabled getEnabled true, false, 1, 0 true Sub GetEnabled (control As IRibbonControl, ByRef returnedVal)
image getImage 1 to 1024 characters (none) Sub GetImage (control As IRibbonControl, ByRef returnedVal)
imageMso getImage 1 to 1024 characters (none) Sub GetImage (control As IRibbonControl, ByRef returnedVal)
keytip getKeytip 1 to 3 characters (none) Sub GetKeytip (control As IRibbonControl, ByRef returnedVal)
label getLabel 1 to 1024 characters (none) Sub GetLabel (control As IRibbonControl, ByRef returnedVal)
maxLength (none) 1 to 1024 characters 1024 (none)
screentip getScreentip 1 to 1024 characters (none) Sub GetScreentip (control As IRibbonControl, ByRef returnedVal)
showImage getShowImage true, false, 1, 0 true Sub GetShowImage (control As IRibbonControl, ByRef returnedVal)
showLabel getShowLabel true, false, 1, 0 true Sub GetShowLabel (control As IRibbonControl, ByRef returnedVal)
sizeString (none) 1 to 1024 characters 12* (none)
supertip getSupertip 1 to 1024 characters (none) Sub GetSupertip (control As IRibbonControl, ByRef returnedVal)
tag (none) 1 to 1024 characters (none) (none)
(none) getText 1 to 4096 characters (none) Sub GetText (control As IRibbonControl, ByRef returnedVal)
visible getVisible true, false, 1, 0 true Sub GetVisible (control As IRibbonControl, ByRef returnedVal)

*The default value for the sizeString attribute (if the attribute is not declared) is approximately 12, but this will vary based on the characters used and the system font.

Using Built-in editBox Controls

Unfortunately, there doesn't seem to be a way to customize any of the built-in editBox controls in Excel.

Creating Custom editBox Controls

The following example creats an editBox that enables the user to rename the sheet.

XML

Copy and paste the following XML code into customUI14.xml:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
	<!-- true: show only your tab in Excel -->
	<ribbon startFromScratch="true">
		<tabs>
			<tab id="customTab"
			     label="Custom Tab">
				<group id="customGroup"
				       label="Custom Group">
					<editBox id="txtRename"
					         label="Rename sheet to:"
					         imageMso="SignatureLineInsert"
					         keytip="R"
					         maxLength="10"
					         sizeString="WWWWWWWWWW"
					         onChange="txtRename_Change"/>
				</group>
			</tab>
		</tabs>
	</ribbon>
</customUI>

VBA

Copy and paste the following VBA code into a normal module:

Option Explicit

Private Function shtRename(sSheetName As String) As Boolean
    On Error Resume Next
    ActiveSheet.Name = sSheetName
    If Err.Number = 0 Then shtRename = True
End Function

'Callback for txtRename onChange
Sub txtRename_Change(control As IRibbonControl, text As String)
    If shtRename(text) = False Then
        MsgBox "There was a problem and I could not" & vbCrLf & _
            "rename your sheet. Please try again.", _
            vbOKOnly + vbCritical, "Error!"
    End If
End Sub

Download

Download Custom editBox Demo.

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>