MistakesWereMade
Board Regular
- Joined
- May 22, 2019
- Messages
- 103
I have a script for my a combobox that is in a userform (GUI). The combo box uses a formula called "DropDownList" that I made to enable a particular type of autocomplete feature to my combo box.
My program works as follows: After I start typing in the combo box and it narrows down my search, I click on the option I want and then press a command button "search" to find and open a file in a folder. When I go to the combo box again to type in a new selection, this is when my program bugs out. I also am not able to close out of the excel file that opens after I "search". I have to manually do it by force closing. I think this has something to do with it.
I've attached pictures and part of my code. Any help would be much appreciated as I just cannot figure it out.
My program works as follows: After I start typing in the combo box and it narrows down my search, I click on the option I want and then press a command button "search" to find and open a file in a folder. When I go to the combo box again to type in a new selection, this is when my program bugs out. I also am not able to close out of the excel file that opens after I "search". I have to manually do it by force closing. I think this has something to do with it.
I've attached pictures and part of my code. Any help would be much appreciated as I just cannot figure it out.
Code:
Dim DisableCb As Boolean
Private Sub CommandButton2_Click()
Dim Wbk As Workbook
Dim Pth As String
Pth = Environ("Userprofile") & "\Desktop\My Files\"
DisableCb = True
On Error Resume Next
Set Wbk = Workbooks.Open(Pth & Me.ComboBox1.Value)
On Error GoTo 0
If Wbk Is Nothing Then
MsgBox "Workbook not found."
End If
ComboBox1.Value = ""
If ComboBox1.Value = "" Then
Dim myRange As Range
Set myRange = ThisWorkbook.Worksheets("Data").Range("E2")
myRange.Clear
End If
DisableCb = False
End Sub
Private Sub ComboBox1_Change()
If DisableCb Then Exit Sub
ComboBox1.RowSource = "DropDownList"
Me.ComboBox1.DropDown
Sheets("Data").Range("E2") = Me.ComboBox1.Value
End Sub