Closing Workbook when Userform closes

Boechat

New Member
Joined
Jul 16, 2016
Messages
44
Greetings everyone,

I'm currently trying to get my excel application to close whenever I close any userform using the red X in the right hand corner. Besides, I'd like the form to throw a prompt asking whether I want to save it or not.
How do I get this done without having to code it into every single form I have (about 40 in this program)?

Thanks in advance
 
If you want to get rid of that message I think you'll either need to save the workbook or disable display alerts.

By the way, why 40 userforms?

Are they connected in anyway?

Perhaps each one connected to a specific sheet?
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
That's it, I do NOT want to get rid of it, I was wondering if it would throw the message naturally without me having to code anything haha
They are all connected, work as a little .exe giving reports and listing inventory, registers, contact lists and such for my firm.
Yepp, they draw information from different sheets and ranges
 
Upvote 0
This might do what you want. The "do you want to save" message should appear automatically as part of the close method
Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
        ThisWorkbook.Close
        Application.Quit
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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