Forms 2.0 Library

When you add a Userform to your project this reference will get automatically added to your VBA project.
Microsoft Forms 2.0 Object Library
This library lets you access the MSForms. Objects

CheckBox 
ComboBox 
CommandButton 
Control 
Controls 
DataObject 
HTMLCheckbox 
HTMLHidden 
HTMLImage 
HTMLOption 
HTMLPassword 
HTMLReset 
HTMLSelect 
HTMLSubmit 
HTMLText 
HTMLTextArea 
Image 
Label 
ListBox 
MSForms.Frame 
MultiPage 
NewFont 
OLE_COLOR 
OLE_HANDLE 
OLE_OPTEXCLUSIVE 
OptionButton 
Page 
Pages 
PIROWSET 
ReturnBoolean 
ReturnEffect 
ReturnInteger 
ReturnSingle 
ReturnString 
ScrollBar 
SpinButton 
Tab 
Tabs 
TabStrip 
TextBox 
ToggleButton 
UserForm 

Private Sub CommandButton1_Click() 
    
   lNewColor = RGB(12, 12, 12)
   
'The MSForms library will be automatically added to the Tools > References
   Dim mscontrol As MSForms.Control
   Dim mstextbox As MSForms.TextBox

   For Each mscontrol In Me.Controls
'The next line will check type of the control
'In this case it is only looking for textboxes.
      If (TypeOf mscontrol Is MSForms.TextBox) Then
'The next line takes the "mscontrol" variable which refers to a 'generic' control
'and copies it to the "mstextbox" variable which has the data type "MSForms.TextBox
'the reason for doing this copying/assigning is to give you full intellisense
         Set mstextbox = mscontrol

         mstextbox.BackColor = lNewColor
      End If
   Next mscontrol
   
'Me. - the object "Me" is a way to refer to the Userform object
'It can only be used in code modules that live behind userforms
   
'Me.Controls - is a way of referring to all the controls that exist on a Userform
   
'The "For Each" allows you to loop through all these controls
'every time a control is identified it is temporarily assigned to the "mstextbox" variable
   
'When you type "mstextbox" followed by a full stop
'you will see all the properties and methods that are specific to a textbox control
   
End Sub


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrev