clsTextboxMask is a powerful VBA class that allows creating textboxes with input masks in Excel and other Office applications. It provides input validation, placeholder display, and visual indication of field fill status.
- Features
- Components
- Installation
- Quick Start
- Main Functions
- Working with Controls
- Style Configuration
- Troubleshooting
- Support for various input mask types (numbers, dates, time, text, regular expressions)
- Real-time input validation
- Display of placeholders with different statuses (empty, partially filled, completely filled, invalid)
- Visual indication of input correctness through border color
- Support for numeric values with range, sign and decimal restrictions
- Support for variable length text
- Support for validation via regular expressions
- Support for placeholder color customization based on field status
- Support for placeholder templates with markers: {mask}, {filled}, {remaining}, {holder}, {RegexPattern}, {RegexFilter}, {percent}
clsTextboxMask.cls: The main textbox mask class implementationfrmTestClass.frm: Test form demonstrating usagemodShowForms.bas: Module containing form display functions- Documentation in the
docs/folder: docs/technical_documentation_eng.md- Technical documentation in Englishdocs/technical_documentation_rus.md- Technical documentation in Russiandocs/user_guide_eng.md- User guide in Englishdocs/user_guide_rus.md- User guide in Russiandocs/implementation_examples_eng.md- Implementation examples in Englishdocs/implementation_examples_rus.md- Implementation examples in Russian
- Copy the
clsTextboxMask.clsfile to your VBA project - Use the class in your UserForms
' Create an instance of clsTextboxMask class
Dim numField As clsTextboxMask
Set numField = New clsTextboxMask
' Add a numeric field with restrictions
Call numField.AddFieldNumeric(inputTextBox:=Me.TextBox1, _
minValue:=0, _
maxValue:=100, _
allowDecimal:=True, _
allowNegative:=False)
' The class automatically applies input mask to the control- Mask Initialization: Methods
AddFieldNumeric,AddFieldDate,AddFieldTime,AddFieldText,AddFieldVariableLength,AddFieldRegexallow applying appropriate masks to textboxes - Input Validation: Automatic validation of input correctness in real-time
- Placeholder Display: Dynamic placeholder text changes depending on field state
- Color Indication: Visual indication of input correctness through border color changes
- Various Format Support: Support for numeric, text, date, time and regular expression formats
The clsTextboxMask class adds input mask functionality to TextBox controls with capabilities:
- Setting minimum and maximum values for numeric fields
- Defining date and time formats
- Applying text masks with various characters
- Using regular expressions for validation
- Configuring border and placeholder colors
The class allows customization of:
- Border colors for correct and incorrect input
- Placeholder text colors for various states
- Display formats for numbers, dates and time
- Placeholder templates using markers
Example of color configuration:
' Configure colors when adding numeric field
Call numField.AddFieldNumeric(inputTextBox:=Me.TextBox1, _
minValue:=0, _
maxValue:=100, _
allowDecimal:=True, _
allowNegative:=False, _
BorderColorValid:=RGB(0, 150, 0), _
BorderColorInvalid:=RGB(200, 0, 0), _
PlaceholderColor:=RGB(150, 150, 150))- Ensure Microsoft Forms 2.0 Object Library is enabled in references
- Check that controls are added before calling class methods
- Ensure the MultiUse property is set to True for the class
- Check that control events are not overloaded with other handlers
- Ensure control properties are not changed manually while the class is running
- Verify that the class is not initialized multiple times
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
