UserForm Objects Label Text Box Command Button Check Box Option Button RefEdit Combo Box UserForm Code Display form: 1-line macro UserFormName.Show All other code event driven User clicks a button User checks a box Text changes in a box Double-click the object to create code Object-Oriented Code Reference Object, Property vText = txtIn.Text Text box – Text RefEdit – Text (“B3”) Option Button – Value (T/F) Check Box – Value (T/F) ComboBox – Text End by closing the form Unload Me Me.Hide Option Button Code Option Buttons – one controls If optRed.Value = True Then Activecell.Font.Color = vbRed ElseIf optBlue.Value = True Then Activecell.Font.Color = vbBlue ElseIf optGreen.Value = True Then Activecell.Font.Color = vbGreen Else Activecell.Font.Color = vbBlack End If Frame: used to group option buttons Check Box Code More than one may occur Each box should have its own “If..Then” If chkBold.Value = True then ActiveCell.Font.Bold = True End If
If chkUnd.Value = True then
ActiveCell.Font.Underline = True End If Advanced Form Example Make it User-Friendly Form Lay-out Tab Stop, Tab Index SetFocus Canceling (clicking the “X”)_ Add a Button Code to Close Cancel Property – Esc key Event-specific Code Change font color in TextBox when option buttons are clicked: Double-click an option button New sub – fill in your action Sub optRed_Click( ) txtData.Font.Color = vbRed End Sub Note this doesn’t change the cell color “Open File” Box Open File Box GetOpenFilename([Filter], [Index], [Title]) Filter – “Description, form” “Text Files (*.txt), *.txt, Excel Files (*.xls), *.xls” Index – number: which item appears as default Returns the name of the file FileName = GetOpenFileName(“All (*.*), *.*”) Returns “False” if user cancels Use to open file Workbooks.Open FileName