The document discusses various objects and code that can be used in Excel user forms including labels, text boxes, command buttons, check boxes, option buttons, combo boxes, and more. It provides examples of how to write code to handle events from these objects and make user-friendly forms.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
17 views
Advanced Dialog Boxes
The document discusses various objects and code that can be used in Excel user forms including labels, text boxes, command buttons, check boxes, option buttons, combo boxes, and more. It provides examples of how to write code to handle events from these objects and make user-friendly forms.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10
More Form Tools
Combo Box (displays a list)
Check Box (yes/no)
Option Button (exclusive choice)
Frame (groups option buttons)
Ref Edit (user selects cells)
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