Not able to close out of excel window

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.
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:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top