Disable Close X on workfile

mwc0914

New Member
Joined
Sep 24, 2015
Messages
42
I have a module in my workbook that builds a new xlsx workfile from data read in other files.
After building the workfile, the module displays a userform with a button (modeless so the user can update the data in the new workfile).
When the user is through updating the workfile, I want to force them to click the button on the userform to save & close the workfile.
I do not want to allow the user to close the workfile by clicking on the X on the workfile.
How can I associate a beforeclose method to the new workfile, to prevent the usage of the X to close the workfile?
Also, when the userform button is pressed, the workfile should save & close.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Have it build a new xlsm instead of xlsx -- actually have a template which the macro opens and uses, and this template (xlxm) has the BeforeClose Event already in it:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = True
MsgBox "Please close via the userform button!"
End Sub
 
Upvote 0
Tried that. When the userform is clicked, it activates the beforeclose method on the workbook & it thinks the closemode = 0, and it throws the msgbox. When clicking on the userform button, it should close.
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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