Fix Backspace in a Word VBA UserForm Text Box
Question details
The user needs to make Backspace work in a Word VBA UserForm text box while preserving leading-zero formatting.

- Product
- Microsoft Word VBA UserForm
- Device & OS
- not provided
- Scenario
- A UserForm text box formats its value with leading zeros as the user edits a three-character entry.
- Observed behavior
- The Change event immediately reformats the value after each keystroke, making Backspace appear not to work.
Open the document in Word, press Alt+F11, and locate the affected UserForm and text box in the VBA editor. Check the text box's Change event for code that rewrites its value.
Format the text box value when the user leaves the field
Move the formatting logic to the Exit event so users can delete and edit characters without immediate reformatting.
In the VBA editor, open the UserForm's code and remove the value-formatting code from Text11_Change. Replace Text11 in the following examples with your text box's actual name.
Select the text box in the UserForm designer, open its code window, and choose Exit from the event list. Add this procedure: Private Sub Text11_Exit(ByVal Cancel As MSForms.ReturnBoolean) If IsNumeric(Me.Text11.Value) Then Me.Text11.Value = Format(Me.Text11.Value, "00#") Else Me.Text11.Value = "N/A" End If End Sub
Add a Text11_KeyPress event to allow digits and Backspace while blocking other typed characters: Private Sub Text11_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii <> 8 And (KeyAscii < 48 Or KeyAscii > 57) Then KeyAscii = 0 End If End Sub
Run the UserForm, type a number in Text11, use Backspace, and then move focus to another control. The value should be formatted only after you leave the field.

Edit Word documents with WPS Office
WPS Office is a free, lightweight alternative for editing Word documents with a familiar interface and a straightforward move from Microsoft Office. It does not repair Word's VBA UserForm events; macro support and compatibility may vary.

Frequently Asked Questions
Why does Backspace seem to do nothing in my UserForm?
A Change event can rewrite the text box after every keystroke. If it immediately adds leading zeros again, a deletion can appear to have no effect.
When does the text box Exit event run?
The Exit event normally runs when focus moves away from the text box to another control. Put the formatting code in Text11_Exit so editing can finish first.
Do I need a Frame Exit event too?
Not necessarily. First test the text box's Exit event by moving focus to another control. The reported case worked without a separate Frame1_Exit procedure.
Does the format 00# restrict entries to three digits?
No. Format(value, "00#") adds leading zeros to make a numeric value at least three digits, but it does not truncate longer numbers. Add separate validation if you need a maximum.
Will the KeyPress event block pasted nonnumeric text?
Not reliably. KeyPress filters typed characters, so use the Exit event's IsNumeric check to validate the final value as well.




