Userform that hides excel closes when new excel workbook is closed

CV899000

Board Regular
Joined
Feb 11, 2016
Messages
98
Hi,

I have a Userform that hides the excel workbook from which it is generated.
This works fine and I use the following code:

Code:
Private Sub Workbook_Open()
Application.Visible = False
General.Show
End Sub

Now, when I hit a commandbutton on my userform that says exit, I wanted excel to stop without asking to save, so I used this code:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
End Sub

This also works fine.

My problem is, that I have another button in my userform that opens a separate workbook and when I am done with this new workbook, I would like to be able to close it and continue with whatever I need in my userform. But when I close this new and separate workbook, the excel that runs my userform also closes.
How can I avoid this?

This also happens if I just open a new excel workbook normally and closes it. No matter what I ONLY want the userform to close if I press the exit button on the userform.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try:

Code:
Private Sub Workbook_Open()
Dim wb As Workbook 
    Set wb = Workbooks(ThisWorkbook.Name)
    Windows(wb.Name).Visible = False 
General.Show
End Sub
 
Last edited:
Upvote 0
Ingolf, thank you for your reply.

This did not work. If I input your code, excel is not hidden anymore (when the userform opens, excel is visible in the background).
I still want excel to be hidden.

And if I open a new excel workbook ontop of my userform and closes the new workbook, my userform still closes.
 
Upvote 0

Forum statistics

Threads
1,214,570
Messages
6,120,297
Members
448,954
Latest member
EmmeEnne1979

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