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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
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,214,945
Messages
6,122,393
Members
449,081
Latest member
JAMES KECULAH

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