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:
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,207
Messages
5,594,841
Members
413,944
Latest member
3xc3ln00b

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
Top