userform Cancel button to keep workbook open

Sven62

Active Member
Joined
Feb 21, 2012
Messages
485
I have disabled the Save/Don'tSave/Cancel prompt that appears on closing the workbook by using
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

Application.ScreenUpdating = False
Call ProtectAllSheets
Call ResetAllSheets
Sheets(1).Activate
    Application.GoTo Range("A1"), Scroll:=True
    Range("A69").Select
Application.ScreenUpdating = True
[B]ThisWorkbook.Saved = True[/B]
If ThisWorkbook.ReadOnly = True Then GoTo Done
UserForm1.Show
Done:
End Sub

UserForm1 has Save/Don't Save/Cancel buttons so I can run a macro if they click Save. (If they click SAVE it saves the workbook and makes a time-stamped backup copy.

QUESTION: How do I make my Cancel button behave like a normal cancel button? That is to say, I want my Cancel button to just unload the userform but leave the workbook open. As it is now it behaves exactly like the Don'tSave button. The userform unloads and the workbook closes.
 
Last edited:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Sven62;4589283
QUESTION: How do I make my Cancel button behave like a normal cancel button? That is to say, I want my Cancel button to just unload the userform but leave the workbook open. As it is now it behaves exactly like the Don'tSave button. The userform unloads and the workbook closes.

Hi,
That event has the Cancel parameter setting it to True when your Cancel button is pressed should prevent workbook closing.

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,582
Members
449,039
Latest member
Arbind kumar

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