- 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 VBA Modern Style UserForms project provides modern styling for MSForms controls in Excel. This tool allows you to easily enhance the appearance of user forms with minimal effort, adding contemporary visual elements and animations.
- Apply modern design to various controls (TextBox, ComboBox, ListBox, CheckBox, OptionButton, etc.)
- Provide focus animation for improved user experience
- Configure colors and fonts for controls
- Add icons and visual elements
- Manage visibility and state of 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
clsModernStyle.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 controls that you want to style
- Add a class variable to the form:
Dim MStyleItem As clsModernStyle- Create a new user form in Excel
- Add several controls (TextBox, ComboBox, CheckBox)
- In the properties window of each control, set the
ControlTipTextproperty with a description - In the
UserForm_Initializeevent, add the following code:
Private Sub UserForm_Initialize()
Set MStyleItem = New clsModernStyle
Call MStyleItem.Initialize(Me)
End Sub- Run the form to see the modern styling of controls
Private Sub UserForm_Initialize()
Set MStyleItem = New clsModernStyle
MStyleItem.Initialize Me, _
ColorBarTitleOn:=RGB(0, 100, 200), _
ColorBarTitleOff:=RGB(120, 120, 120), _
ColorBarBottomOn:=RGB(0, 100, 200), _
ColorBarBottomOff:=RGB(180, 180, 180), _
ColorBackGroundOn:=RGB(255, 255, 255), _
ColorBackGroundOff:=RGB(245, 245, 245)
End SubThe Initialize method is the main way to apply styles to all controls on a form:
- Automatically recognizes all supported controls
- Applies modern styles to all elements
- Creates additional visual elements (lines, titles, icons)
- Sets up event handlers for focus animation
- TextBox - text fields with title animation and clear button
- ComboBox - combo boxes with animation and arrow
- ListBox - lists with enhanced visual styling
- CheckBox - checkboxes with modern styling
- OptionButton - option buttons with circular icons
- Frame - frames (no style changes)
- Label - labels (no style changes)
- CommandButton - buttons (no style changes)
For text boxes, the class automatically:
- Applies transparent background and flat border style
- Adds a bottom line that changes color on focus
- Creates an animated title that moves when text is entered
- Adds an icon on the left (if specified in the Tag property)
- Provides a clear button (appears when text is entered)
For combo boxes, the class:
- Hides the standard dropdown arrow
- Adds a custom arrow with animation
- Applies transparent background
- Provides focus animation similar to text boxes
- Adds a clear button when needed
For lists, the class:
- Applies border style
- Adds bottom line and title
- Provides animation when selecting items
- Supports scrolling and multiple item selection
For checkboxes and option buttons, the class:
- Replaces standard controls with styled icons
- Provides visual feedback when changing state
- Supports different styles for active and inactive states
- Allows creating modern toggle switches (see "Creating Toggle Switches" section)
The class provides extensive color configuration options:
- Title colors (active/inactive state)
- Bottom line colors (active/inactive state)
- Background colors (active/inactive state)
- Icon colors (active/inactive state)
- Dropdown arrow colors
- Toggle border colors
- Checkbox button colors
Colors can be configured during initialization:
MStyleItem.Initialize Me, _
ColorBarTitleOn:=RGB(255, 0, 0), _
ColorBarTitleOff:=RGB(128, 128, 128), _
ColorBarBottomOn:=RGB(0, 0, 255), _
ColorBarBottomOff:=RGB(192, 192, 192)After initialization, you can change colors for individual elements:
With MStyleItem.getItemByName(TextBox1.Name)
.ColorBackGroundOff = vbRed
.ColorBackGroundOn = vbGreen
End WithThe class automatically:
- Sets the font name (default Segoe UI)
- Configures font sizes for active and inactive states
- Supports font size configuration via
FontSizeTitleOffandFontSizeTitleOnproperties
To create a modern toggle switch instead of a regular checkbox:
- In the form designer, set the
Tagproperty of the checkbox to "SWITCH" - Or programmatically:
MyCheckBox.Tag = "SWITCH"- When initializing styles, the checkbox will be displayed as a modern toggle switch with animation
- Regular toggle - circular button with animation
- Styled toggle - using icons from the enumIcons enumeration
- Custom toggle - with configurable colors and sizes
The class includes an enumIcons enumeration with various icons:
- ArrowOff, ArrowOn (for dropdowns)
- CheckBox1, CheckboxComposite, CheckboxFill
- CheckMark
- CircleFill, CircleRing (for option buttons)
- FavoriteStar, FavoriteStarFill
- Heart, HeartFill
- PasswordChar
- RadioBtnOff, RadioBtnOn
- ToggleOff, ToggleOn, ToggleThumb
To add an icon to a control:
- In the form designer, set the
Tagproperty of the control to the numeric value of the icon - Or programmatically:
MyTextBox.Tag = 59193 ' Using numeric value for icon
' Or
MyTextBox.Tag = "61735" ' Using string value for icon- The icon will appear to the left of the control
- Icons are displayed using the Segoe MDL2 Assets font
- Icon color changes depending on the control state
- Icons automatically scale to the control size
After initialization, all styled controls are stored in a collection:
' Getting element by name
Dim item As clsModernStyle
Set item = MStyleItem.getItemByName(TextBox1.Name)
' Getting element by index
Set item = MStyleItem.getItemByIndex(1)Dim count As Byte
count = MStyleItem.CountDim item As clsModernStyle
For Each item In MStyleItem.StyleItems
' Processing each element
Debug.Print item.Name
Next item' Changing background color of a specific element
With MStyleItem.getItemByName(TextBox1.Name)
.ColorBackGroundOn = RGB(255, 255, 200)
.ColorBackGroundOff = RGB(255, 255, 255)
End With- Ensure Microsoft Forms 2.0 Object Library is enabled in references
- Check that all controls are 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 number of controls on the form
- Avoid frequent calls to methods for getting elements from the collection
- Use visibility and availability properties instead of removing elements
- "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 getItemByName or getItemByIndex methods to get a specific element and change its color properties.
Answer: The class supports main MSForms controls. Some controls (e.g., ScrollBar, SpinButton) are supported partially.
Answer: Yes, you can create multiple class instances for different forms, but it's not recommended to use multiple instances for one form.
Answer: The class uses the Segoe MDL2 Assets font, which contains many built-in icons. For custom icons, you can use images or characters from other fonts.
Answer: The class is tested with Excel 2010 and newer. Compatibility with earlier versions is not guaranteed.
Answer: The current version does not provide direct animation configuration, but you can change visual effects through color properties and font sizes.
Answer: Events of original controls continue to work as usual. The class only adds visual effects and does not change event handling logic.