MistakesWereMade
Board Regular
- Joined
- May 22, 2019
- Messages
- 103
So I made a program that allows me to open files in a folder on my desktop. To make the program more user friendly, I decided to enable a UserForm that is the only window open when the excel file/program is clicked on. I did put a command button that reveals the original excel file.
When I "search" using my userform to open some file, the new file opens and then is basically permanent... I don't know why I can't click the exit in the upper right hand corner. It seems to be completely locked. I have to right click the application down below and manually close out of excel entirely. With my previous program before the userform, I was able to close the new window properly and then open more files and so forth. I want the userform to stay open, while the new excel file can remain open or be closed. I have a feeling that the reason why the newly opened excel files cannot be closed is because I have my program running where the worksheet is hidden and the userform, only, is visible. Therefore, when I programmably open a new file in the worksheet that is coded to be hidden, it just kinda sits there because it shouldn't be visible? I'm not really sure how to fix this or if it is even the problem. Could anyone help me with pinpointing or a solution?
The code below is my code for the workbook.
The code below is my code for the userform.
When I "search" using my userform to open some file, the new file opens and then is basically permanent... I don't know why I can't click the exit in the upper right hand corner. It seems to be completely locked. I have to right click the application down below and manually close out of excel entirely. With my previous program before the userform, I was able to close the new window properly and then open more files and so forth. I want the userform to stay open, while the new excel file can remain open or be closed. I have a feeling that the reason why the newly opened excel files cannot be closed is because I have my program running where the worksheet is hidden and the userform, only, is visible. Therefore, when I programmably open a new file in the worksheet that is coded to be hidden, it just kinda sits there because it shouldn't be visible? I'm not really sure how to fix this or if it is even the problem. Could anyone help me with pinpointing or a solution?
The code below is my code for the workbook.
Code:
Private Sub Workbook_Open()
Application.Visible = False
UserForm1.Show
End Sub
The code below is my code for the userform.
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
DisableCb = False
End Sub
Private Sub ComboBox1_Change()
If DisableCb Then Exit Sub
Sheets("Data").Range("E2") = Me.ComboBox1.Value
ComboBox1.RowSource = "DropDownList"
Me.ComboBox1.DropDown
End Sub
Private Sub CommandButton1_Click()
Application.DisplayAlerts = False
Application.Quit
End Sub
Private Sub CommandButton3_Click()
Application.Visible = True
Me.Hide
End Sub
Last edited: