Welcome to FreeSoftwareServers Confluence Wiki

Simple Example of a ComboBox in a UserForm with a CommandButton.

All names used are "default" IE: UseForm1, ComboBox1,CommandButton1 etc

This is the "UserForm1" code. Add a ComboBox and a CommandButton then this code to userform.

Private Sub CommandButton1_Click()

If ComboBox1.Value = "Win" Then
    MsgBox "Win"
    Unload Me ' Close UserForm
End If

End Sub

Private Sub UserForm_Initialize()
' Center UserForm
Me.Top = Application.Top + (Application.UsableHeight / 2) - (Me.Height / 2)
Me.Left = Application.Left + (Application.UsableWidth / 2) - (Me.Width / 2)
ComboBox1.Style = fmStyleDropDownList
'ComboBox.List = Array("Choose a Single File", "Choose Multiple Files")
ComboBox1.AddItem "Win", 0 'add item to top of combobox
ComboBox1.AddItem "Lose" ' , .ListIndex 'add item to bottom of combobox List Array
ComboBox1.AddItem "Tie", 2 'add item to third spot in userform

End Sub

Then create a Module with the folliwing and run:

Sub CBUFShow()
End Sub





  • No labels