Presentation is loading. Please wait.

Presentation is loading. Please wait.

More Form Tools Combo Box (displays a list) Check Box (yes/no) Frame (groups option buttons) Option Button (exclusive choice) Ref Edit (user selects cells)

Similar presentations


Presentation on theme: "More Form Tools Combo Box (displays a list) Check Box (yes/no) Frame (groups option buttons) Option Button (exclusive choice) Ref Edit (user selects cells)"— Presentation transcript:

1 More Form Tools Combo Box (displays a list) Check Box (yes/no) Frame (groups option buttons) Option Button (exclusive choice) Ref Edit (user selects cells)

2 UserForm Objects Text Box Command Button Option Button Check Box RefEdit Combo Box Label

3 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

4 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

5 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

6 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

7 Advanced Form Example

8 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

9 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

10 “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


Download ppt "More Form Tools Combo Box (displays a list) Check Box (yes/no) Frame (groups option buttons) Option Button (exclusive choice) Ref Edit (user selects cells)"

Similar presentations


Ads by Google