This repository contains a VBA implementation of a multi-state checkbox control that can be used in Excel UserForms. The checkbox class provides three or more states (unchecked, checked, indeterminate) with customizable appearance and behavior.
- Features
- Components
- Installation
- Quick Start
- Main Functions
- Working with Controls
- Style Configuration
- Troubleshooting
- Three-state checkbox functionality (unchecked, checked, indeterminate)
- Customizable appearance and behavior
- Easy integration with VBA UserForms
- Reusable class module for consistent checkbox behavior
- Cyclic/non-cyclic state switching (property
Cyclic) - Ability to set/get state by text (property
StateText) - Method to get all available states (
GetAllStates) - Improved error handling and validation
- Ability to set font name and size factor (properties
FontNameandFontSizeFactor) - Ability to get/set current icon (property
CurrentIcon) - Method to set color for specific state (
SetStateColor) - Method to reset to initial state (
ResetToInitialState)
clsMultiStateCheckBox.cls: The main checkbox 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 English
docs/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
- Download the
clsMultiStateCheckBox.clsfile from thevba-files/Class/directory - Import the class into your VBA project
- Ensure you have the Microsoft Forms 2.0 Object Library referenced in your project
' Create an instance of clsMultiStateCheckBox class
Set MultiStateCheckBox = New clsMultiStateCheckBox
' Initialize the checkbox using a Label control
Call MultiStateCheckBox.Initialize(Me.Label1)
' The class automatically applies multi-state functionality to the control- Checkbox Initialization: The
Initializemethod allows setting the initial state and configuring the checkbox appearance - State Management: Support for three or more states (unchecked, checked, indeterminate and others)
- Color Configuration: Ability to configure colors for each state
- Icon Support: Using icons for various checkbox states
- Cyclic Switching: Ability to enable/disable cyclic switching between states
The clsMultiStateCheckBox class converts a regular Label control into a multi-state checkbox with capabilities:
- Setting initial state
- Configuring appearance for each state
- Handling click events for state switching
- Accessing current checkbox state
The class allows customization of:
- Colors for each checkbox state
- Icons for each state
- Fonts and text sizes
- Interaction behavior (cyclic behavior, reset to initial state)
Example of color configuration:
' Configure colors for different states
Dim colors As Variant
colors = Array(vbRed, vbGreen, vbBlue) ' Colors for each state
MultiStateCheckBox.Initialize Me.Label1, 0, Array(59193, 59194, 59195), colors- Ensure Microsoft Forms 2.0 Object Library is enabled in references
- Check that the Label control is added before calling the Initialize method
- 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.
