- Introduction
- System Requirements
- Installation and Setup
- Quick Start
- Main Features
- Working with Controls
- Style Configuration
- Creating Toggle Switches
- Adding Icons
- Working with Style Collection
- Troubleshooting
- Frequently Asked Questions
The clsSlider class implements a custom slider control for VBA UserForms. The slider allows users to select a value within a specified range by dragging a button along a track. It supports both horizontal and vertical orientations and provides customizable appearance and behavior options.
- Apply modern design to slider controls
- Provide smooth value selection with visual feedback
- Configure colors and fonts for sliders
- Add icons and visual elements
- Manage visibility and state of slider controls
- Microsoft Excel (2010 or newer recommended)
- VBA support enabled
- Microsoft Forms 2.0 Object Library
- Windows 7 or newer
- Open Excel and go to the VBA editor (press Alt+F11)
- In the menu, select "File" > "Import File"
- Select the
clsSlider.clsfile from thevba-files/Class/directory - Click "Open" to import the class
- In the VBA editor, select "Tools" > "References"
- Find and check the box next to "Microsoft Forms 2.0 Object Library"
- Click "OK" to save changes
- In the VBA editor, create a new user form
- Add a Label control that will serve as the slider track
- Add a class variable to the form:
Dim Slider As clsSlider- Create a new user form in Excel
- Add a Label control to serve as the slider track
- In the
UserForm_Initializeevent, add the following code:
Private Sub UserForm_Initialize()
Set Slider = New clsSlider
Call Slider.Initialize(Me.Label1, 50, 0, 100, True)
End Sub- Run the form to see the slider control
Private Sub UserForm_Initialize()
Set Slider = New clsSlider
Call Slider.Initialize(Me.Label1, 50, 0, 100, True, , , RGB(200, 200, 200), RGB(0, 100, 200), RGB(0, 0, 0), RGB(0, 0, 0))
End SubThe Initialize method is the main way to set up the slider:
- Sets the initial value, minimum and maximum values
- Configures appearance properties
- Sets up event handlers for interaction
- Creates value label if enabled
- Horizontal - slider moves left and right
- Vertical - slider moves up and down
- Automatic detection based on control dimensions
For sliders, the class automatically:
- Applies the specified value range
- Creates a movable button element
- Shows a value label with positioning options
- Provides visual feedback during interaction
- Handles mouse events for dragging
The class allows configuring:
- Minimum and maximum values
- Initial value
- Value display format
- Position of the value label
The class provides events for:
- Value changes during interaction
- Click events on the slider button
- Visual feedback during dragging
The class provides extensive color configuration options:
- Track colors (empty/filled portions)
- Button colors
- Value label colors
- Background colors
Colors can be configured during initialization:
Slider.Initialize Me.Label1, 50, 0, 100, True, , , RGB(200, 200, 200), RGB(0, 100, 200)After initialization, you can change properties:
With Slider
.BackColorFull = RGB(255, 0, 0)
.ForeColorValue = RGB(0, 0, 255)
End WithThe class allows:
- Setting font size for value labels
- Configuring font properties via
FormatValueproperty
The clsSlider class does not implement toggle switches directly. For toggle switches, consider using the clsMultiStateCheckBox class with the SWITCH tag property.
The slider class uses icons primarily for the slider button:
- Customizable button appearance
- Unicode character support
- Font configuration for icons
To customize the slider button:
- In the Initialize method, specify the Icon parameter
- Or programmatically:
Slider.Icon = 59963 ' Using numeric value for icon- Icons are displayed using the Segoe MDL2 Assets font by default
- Icon color changes depending on the slider state
- Icons automatically scale to the button size
After initialization, the slider provides access to its elements:
' Getting slider properties
Dim currentValue As Single
currentValue = Slider.ValueThe slider class manages a single control element, but provides access to its properties.
The slider class focuses on a single control, so iteration is not typically necessary.
' Changing slider properties
With Slider
.Value = 75
.MinValue = 0
.MaxValue = 100
End With- 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
- Reduce the complexity of value formatting
- Avoid frequent calls to property getters during interaction
- Use visibility and availability properties appropriately
- "Object variable not set" - ensure the class variable is properly initialized
- "Method or data member not found" - check that the class is properly imported
- "Can't assign to property" - avoid direct assignment to nested objects without checking for Nothing
Answer: Use the properties of the slider instance to change colors after initialization.
Answer: The class specifically supports slider functionality using Label controls as tracks.
Answer: Yes, you can create multiple class instances for different sliders, but each instance manages a single slider control.
Answer: The class uses Unicode character values for icons. For custom icons, you can use different character codes or consider using image controls.
Answer: The class is tested with Excel 2010 and newer. Compatibility with earlier versions is not guaranteed.
Answer: The current version provides smooth value transition during dragging, but direct animation configuration is not available.
Answer: The class provides Click and value change events that can be handled in the form module.