Skip to content

A VBA class implementation that provides a multi-state checkbox control with three or more states: unchecked, checked, and indeterminate.

License

Notifications You must be signed in to change notification settings

vbatools/UserForms-Class-Multi-State-CheckBox-VBA

Repository files navigation

VBA Multi-State Checkbox Class

Project Demo

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.

Table of Contents

  1. Features
  2. Components
  3. Installation
  4. Quick Start
  5. Main Functions
  6. Working with Controls
  7. Style Configuration
  8. Troubleshooting

Features

  • 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 FontName and FontSizeFactor)
  • Ability to get/set current icon (property CurrentIcon)
  • Method to set color for specific state (SetStateColor)
  • Method to reset to initial state (ResetToInitialState)

Components

Installation

  1. Download the clsMultiStateCheckBox.cls file from the vba-files/Class/ directory
  2. Import the class into your VBA project
  3. Ensure you have the Microsoft Forms 2.0 Object Library referenced in your project

Quick Start

Simple Usage Example

' 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

Main Functions

  • Checkbox Initialization: The Initialize method 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

Working with Controls

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

Style Configuration

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

Troubleshooting

Display Issues

  • 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

Interaction Issues

  • 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

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

About

A VBA class implementation that provides a multi-state checkbox control with three or more states: unchecked, checked, and indeterminate.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages