Private Sub UserForm_Initialize()
Dim Cn As String, Rs As Object
Cn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.FullName & ";Extended Properties=""Excel 12.0;HDR=YES;"""
Set Rs = CreateObject("AdoDb.RecordSet")
Rs.Open "Select * from [Combo$]", Cn
Me.ComboBox1.Column = Rs.getrows
Rs.Close
Set Rs = Nothing
End Sub
Private Sub ComboBox1_Click()
If ComboBox1.ListIndex > -1 Then
MsgBox ComboBox1.Text
End If
End Sub
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
If ComboBox1.ListIndex = -1 And ComboBox1.Text <> "" Then
ComboBox1.AddItem ComboBox1.Text
ComboBox1.ListIndex = ComboBox1.ListCount - 1
End If
ComboBox1_Click
End If
End Sub