- Class Overview
- Class Architecture
- Properties
- Methods
- Events
- Constants and Enumerations
- Implementation Details
- Dependencies
The VBA Modern Style UserForms project is a VBA class library designed to style MSForms controls in Excel. The main class clsModernStyle implements modern visual effects, animations, and enhanced visual feedback for custom forms.
The clsModernStyle class is designed to apply modern design to MSForms controls with implementations of visual effects such as focus animation, color and font configuration, adding icons and visual elements.
- Applying modern style to various controls (TextBox, ComboBox, ListBox, CheckBox, OptionButton, etc.)
- Supporting focus animation
- Configuring color and font
- Adding icons and visual elements
- Managing visibility and state of controls
The class uses events to track changes in controls:
Private WithEvents mUserForm As MSForms.UserForm
Private WithEvents mTextBox As MSForms.TextBox
Private WithEvents mComboBox As MSForms.ComboBox
Private WithEvents mListBox As MSForms.ListBox
Private WithEvents mFrame As MSForms.Frame
Private WithEvents mLabel As MSForms.label
Private WithEvents mCommandButton As MSForms.CommandButton
Private WithEvents mCheckBox As MSForms.CheckBox
Private WithEvents mOptionButton As MSForms.OptionButtonThe class stores information about controls in a collection:
mStyleItems- collection of all style itemsmControl- main controlmControlType- control typemControlName- control namemControlTipText- tooltip text
| Property | Type | Description |
|---|---|---|
control |
MSForms.control | The main control being styled |
ControlType |
String | The type of control (e.g., "TextBox", "ComboBox") |
Name |
String | The name of the control |
ControlTipText |
String | The tooltip text for the control |
Visible |
Boolean | The visibility of the control and all associated style elements |
Locked |
Boolean | The locking state of the control and all associated style elements |
Enabled |
Boolean | The enabled state of the control and all associated style elements |
top |
Single | The top position of the control |
left |
Single | The left position of the control |
height |
Single | The height of the control |
width |
Single | The width of the control |
FontSizeTitleOff |
Integer | The font size for inactive state |
FontSizeTitleOn |
Integer | The font size for active state |
FontName |
String | The font name for the control |
control- Gets or sets the main control that will be styledControlType- Gets or sets the type of control (e.g., "TextBox", "ComboBox")Name- Gets or sets the name of the controlControlTipText- Gets or sets the tooltip text for the control
Visible- Gets or sets the visibility of the control and all associated style elementsLocked- Gets or sets the locking state of the control and all associated style elementsEnabled- Gets or sets the enabled state of the control and all associated style elements
top- Gets or sets the top position of the controlleft- Gets or sets the left position of the controlheight- Gets or sets the height of the controlwidth- Gets or sets the width of the control
FontSizeTitleOff- Gets or sets the font size for inactive stateFontSizeTitleOn- Gets or sets the font size for active stateFontName- Gets or sets the font name for the control
ColorBarTitleOn- Gets or sets the title color in active stateColorBarTitleOff- Gets or sets the title color in inactive stateColorBarBottomOn- Gets or sets the bottom line color in active stateColorBarBottomOff- Gets or sets the bottom line color in inactive stateColorBackGroundOn- Gets or sets the background color in active stateColorBackGroundOff- Gets or sets the background color in inactive stateColorBarIconOn- Gets or sets the icon color in active stateColorBarIconOff- Gets or sets the icon color in inactive stateColorDropArrowOn- Gets or sets the dropdown arrow color in active stateColorDropArrowOff- Gets or sets the dropdown arrow color in inactive stateColorTgBorderOn- Gets or sets the toggle border color in active stateColorTgBorderOff- Gets or sets the toggle border color inactive stateColorChkBoxBtnOn- Gets or sets the checkbox button color in active stateColorChkBoxBtnOff- Gets or sets the checkbox button color in inactive stateColorChkBoxCaptionOn- Gets or sets the checkbox caption color in active stateColorChkBoxCaptionOff- Gets or sets the checkbox caption color in inactive state
ChrDropArrowOn- Gets or sets the dropdown arrow character in active stateChrDropArrowOff- Gets or sets the dropdown arrow character in inactive stateChrChkBoxBtnOn- Gets or sets the checkbox button character in active stateChrChkBoxBtnOff- Gets or sets the checkbox button character in inactive stateChrOptBoxBtnOn- Gets or sets the option button character in active stateChrOptBoxBtnOff- Gets or sets the option button character in inactive state
BarBottom- Gets or sets the bottom line of the controlBarTitle- Gets or sets the title of the controlBarIcon- Gets or sets the icon of the controlBackGround- Gets or sets the background of the controlDropArrow- Gets or sets the dropdown arrowBtnClear- Gets or sets the clear buttonTgBorder- Gets or sets the toggle borderChkBoxBtn- Gets or sets the checkbox buttonChkBoxCaption- Gets or sets the checkbox caption
StyleItems- Gets or sets the collection of all style itemsCount- Gets the number of items in the collectiongetItemByIndex- Gets an item from the collection by indexgetItemByName- Gets an item from the collection by nameVersion- Gets version information about the class
Initialize- Initializes style for all form controls
Syntax:
Public Sub Initialize(ByRef Form As MSForms.UserForm, _
Optional ColorBarTitleOn As XlRgbColor = 14854934, _
Optional ColorBarTitleOff As XlRgbColor = 10395294, _
Optional ColorBarBottomOn As XlRgbColor = 14854934, _
Optional ColorBarBottomOff As XlRgbColor = 10395294, _
Optional ColorBackGroundOn As XlRgbColor = vbWhite, _
Optional ColorBackGroundOff As XlRgbColor = 16447476, _
Optional ColorBarIconOn As XlRgbColor = 14854934, _
Optional ColorBarIconOff As XlRgbColor = 10395294, _
Optional ColorDropArrowOn As XlRgbColor = vbBlack, _
Optional ColorDropArrowOff As XlRgbColor = 10395294, _
Optional ColorTgBorderOn As XlRgbColor = 14854934, _
Optional ColorTgBorderOff As XlRgbColor = 10395294, _
Optional ColorChkBoxBtnOn As XlRgbColor = vbBlack, _
Optional ColorChkBoxBtnOff As XlRgbColor = 10395294, _
Optional ChrDropArrowOn As enumIcons = ArrowOn, _
Optional ChrDropArrowOff As enumIcons = ArrowOff, _
Optional ColorChkBoxCaptionOn As XlRgbColor = 14854934, _
Optional ColorChkBoxCaptionOff As XlRgbColor = 10395294, _
Optional ChrChkBoxBtnOn As enumIcons = CheckboxComposite, _
Optional ChrChkBoxBtnOff As enumIcons = CheckBox1, _
Optional ChrOptBoxBtnOn As enumIcons = CircleFill, _
Optional ChrOptBoxBtnOff As enumIcons = CircleRing)Parameters:
Form- reference to UserForm to which style is appliedColorBarTitleOn- title color in active state (default 14854934)ColorBarTitleOff- title color in inactive state (default 10395294)ColorBarBottomOn- bottom line color in active state (default 14854934)ColorBarBottomOff- bottom line color in inactive state (default 10395294)ColorBackGroundOn- background color in active state (default vbWhite)ColorBackGroundOff- background color inactive state (default 1647476)ColorBarIconOn- icon color in active state (default 14854934)ColorBarIconOff- icon color inactive state (default 10395294)ColorDropArrowOn- dropdown arrow color in active state (default vbBlack)ColorDropArrowOff- dropdown arrow color in inactive state (default 10395294)ColorTgBorderOn- toggle border color in active state (default 14854934)ColorTgBorderOff- toggle border color in inactive state (default 10395294)ColorChkBoxBtnOn- checkbox button color in active state (default vbBlack)ColorChkBoxBtnOff- checkbox button color inactive state (default 10395294)ChrDropArrowOn- dropdown arrow character in active state (default ArrowOn)ChrDropArrowOff- dropdown arrow character in inactive state (default ArrowOff)ColorChkBoxCaptionOn- checkbox caption color in active state (default 14854934)ColorChkBoxCaptionOff- checkbox caption color in inactive state (default 10395294)ChrChkBoxBtnOn- checkbox button character in active state (default CheckboxComposite)ChrChkBoxBtnOff- checkbox button character in inactive state (default CheckBox1)ChrOptBoxBtnOn- option button character in active state (default CircleFill)ChrOptBoxBtnOff- option button character in inactive state (default CircleRing)
ApplyControlStyle- applies style depending on control typeSetCommonStyleProperties- sets common style properties for a controlsetTextBoxStyle- sets style for text boxsetComboBoxStyle- sets style for combo boxsetListBoxStyle- sets style for list box
CreateStyledLabel- creates and configures main properties of additional elementSetCommonFontProperties- sets common font properties for a controladdBarBottom- adds bottom style line for controladdBarTitle- adds style title for controladdBarIcon- adds style icon for controladdBackGround- adds style background for controladdDropArrow- adds dropdown arrow style for controladdBtnClear- adds clear button style for controladdCheckBox- adds checkbox style for controladdCheckBoxSwitch- adds toggle switch style for control
HandleExitEvent- reset style for all controlsexitControl- reset control style on focus lossbtnClearVisible- managing visibility of clear button for controlHandleEnterEvent- activating control style on focus gain
mTextBox_Change- text change event in text boxmTextbox_MouseDown- mouse click event on text boxmTextbox_KeyUp- key release event when focused on text box
mComboBox_Change- value change event in combo boxmComboBox_KeyUp- key release event when focused on combo boxmComboBox_MouseDown- mouse click event on combo box
mListBox_Change- value change event in list boxmListBox_MouseDown- mouse click event on list boxmListBox_KeyUp- key release event when focused on list box
mUserForm_Click- click event on user formmFrame_Click- click event on framemLabel_Click- click event on labelmCommandButton_Click- click event on command button
mDropArrow_Click- click event on dropdown arrowmBtnClear_Click- click event on clear buttonmChkBoxBtn_Click- click event on checkbox buttonmTgBorder_Click- click event on toggle bordermCheckBox_Change- checkbox state change eventmChkBoxCaption_Click- click event on checkbox captionmOptionButton_Change- option button state change event
Public Enum enumIcons
ArrowOff = &HE011 ' Dropdown list arrow (off)
ArrowOn = &HE010 ' Dropdown list arrow (on)
CheckBox1 = 59193 ' Square (normal)
Checkbox14 = 61803 ' Square (small)
CheckboxComposite = 59194 ' Square with checkmark
CheckboxComposite14 = 61804 ' Square with checkmark (small)
CheckboxCompositeReversed = 59197 ' Square with checkmark (reversed)
CheckboxIndeterminateCombo = 61806 ' Square with dash
CheckboxIndeterminateCombo14 = 61805 ' Square with dash (small)
CheckboxFill = 59195 ' Square (filled)
CheckMark = 59198 ' Checkmark
CircleFill = 59963 ' Circle (filled)
CircleRing = 59962 ' Circle (outline)
FavoriteStar = 5918 ' Star (normal)
FavoriteStarFill = 59189 ' Star (filled)
Heart = 60241 ' Heart (normal)
HeartFill = 60242 ' Heart (filled)
InkingColorFill = 60775 ' Brush (filled)
InkingColorOutline = 6074 ' Brush (outline)
PaginationDotOutline10 = 61734 ' Dot (outline)
PaginationDotSolid10 = 61735 ' Dot (filled)
PasswordChar = 149 ' Character for hiding password
RadioBtnOff = 60618 ' Radio button (off)
RadioBtnOn = 60619 ' Radio button (on)
ToggleOff = 60434 ' Toggle switch (off)
ToggleOn = 60433 ' Toggle switch (on)
ToggleThumb = 60436 ' Toggle switch thumb
End Enum' Font constants
Private Const FONT_NAME_ICON As String = "Segoe MDL2 Assets"
' Constants for control types
Private Const CONTROL_TYPE_TEXTBOX As String = "TextBox"
Private Const CONTROL_TYPE_COMBOBOX As String = "ComboBox"
Private Const CONTROL_TYPE_LISTBOX As String = "ListBox"
Private Const CONTROL_TYPE_CHECKBOX As String = "CheckBox"
Private Const CONTROL_TYPE_OPTIONBUTTON As String = "OptionButton"
Private Const CONTROL_TYPE_FRAME As String = "Frame"
Private Const CONTROL_TYPE_LABEL As String = "Label"
Private Const CONTROL_TYPE_COMMANDBUTTON As String = "CommandButton"
Private Const CONTROL_TYPE_MULTI_PAGE As String = "MultiPage"
Private Const CONTROL_TYPE_IMAGE As String = "Image"
Private Const CONTROL_TYPE_TABSTRIP As String = "TabStrip"
Private Const CONTROL_TYPE_SCROLLBAR As String = "ScrollBar"
Private Const CONTROL_TYPE_SPINBUTTON As String = "SpinButton"
' Constants for additional control names
Private Const BAR_BOTTOM As String = "_barBottom"
Private Const BAR_TITLE As String = "_barTitle"
Private Const BAR_ICON As String = "_barIcon"
Private Const BACK_GROUND As String = "_BackGround"
Private Const DROP_ARROW As String = "_DropArrow"
Private Const BTN_CLEAR As String = "_BtnClear"
' Constants for control behavior
Private Const CONTROL_SWITCH As String = "SWITCH"UpdateSwitchState- internal method to update switch stateUpdateSwitchVisualState- internal method to update switch visual stateIsControlActive- helper method to check if control is activeConfigureStyleElement- internal method for configuring style element propertiesIsControlInCollection- check if control already exists in the collectionSetControlEnabled- internal method to set the availability state of a controlSetControlVisibility- internal method to set the visibility of a controlSetControlLock- internal method to set the locking state of a control
Class_Terminate- clean up objects when class is terminated
- Microsoft Forms 2.0 Object Library
- VBA runtime environment