Close the workbook when the user form is closed

sanrv1f

MrExcel MVP
Joined
Jan 1, 2009
Messages
3,474
Office Version
  1. 2016
Platform
  1. Windows
Hi

Im using an user form to design a calculator

once the user closes the form, I want the work book also to get closed without asking the user to save changes

here is the code I used

Private Sub UserForm_Terminate()

ThisWorkbook.Close savechanges:=False
End Sub

this code works fine and closes the excel without prompting for saving, but excel hangs after that, pls help me with this
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
If you mean that you want to exit Excel as well try

Code:
Private Sub UserForm_Terminate()
ThisWorkbook.Close savechanges:=False
Application.Quit
End Sub
 
Upvote 0
Sankar

'Hangs' in what way?

Perhaps this is what you want.
Code:
Application.Quit
 
Upvote 0
Hi

"Hangs" means the cursor changes to hour-glass and nothing happens thereafter, if there is no other workbooks are open,
if there is someother workbook open, then excel closes and generates an error report,

I dont want to quit the application, I just want the current workbook to close without saving, along with the form and, other open workbooks need remain open,

Also tell me, is there any way to open a workbook exclusively under an application and any other workbook the user opens to open under a different application
 
Upvote 0

Forum statistics

Threads
1,214,638
Messages
6,120,674
Members
448,977
Latest member
moonlight6

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