Workbook_BeforeClose macro question

imonline

New Member
Joined
Apr 16, 2002
Messages
9
I need for a message to appear when a user closes a workbook. If the user clicks "YES" it opens a userform. I wrote the code in the "Workbook_BeforeSave" sub and the msg opens fine but when I click "Yes" my userform barely starts and the workbook closes.

Is there a way to suspend the workbook to close until I've finished using my userform.

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

Dim Msg, Style, Title, Response
Msg = "Do you want to change the date?"   
Style = vbYesNo + vbCritical + vbDefaultButton2   
Title = "Change Date"
   
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then 
Load UserForm1
UserForm1.Show

End If
End Sub
Can someone please help :oops:
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
What's your User Form code?

If you're dismissing the form to have a user change the date on a sheet, then the wb will close unless you add Exit Sub. You could change the date through the form though.

And you can get rid of Load UserForm1 as the two statements together are erroneous.

Hope that helps,

Smitty
 
Upvote 0

Forum statistics

Threads
1,215,333
Messages
6,124,317
Members
449,153
Latest member
JazzSingerNL

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