Hi all
I'm trying to run a macro that will ensure some variables are met and won't allow the workbook to close if not. I know how to run the macro on close, but is there a code to stop the workbook from closing then?
Thanks
Alan
Last edited by alanb1976; 01-23-2012 at 11:37 AM.
The before close Event has a cancel argument, you can set this to true to stop the workbook closing
Click the * below to say thanks
Girls sleep with guys who use photoshop, but marry the ones who work with Excel
Corduroy pillows: They're making headlines!
Did you mean: recursion
http://www.google.com/search?hl=en&q=recursion
Try "cancel", no quotes if your conditions are not met
as an option
Private Sub Workbook_BeforeClose(Cancel As Boolean) '''''''change here for yr condition If Range("A1") < 1000 Then MsgBox "The total in A1 must be at least 1000!" _ & " Please complete worksheet before closing.", vbExclamation, "Warning!" Cancel = True End If End Sub
Regards, John
Thanks. That worked
you're welcome!
If your problem is solved, please say so clearly, and mark your thread as Solved:
Click the Edit button on your first post in the thread,
Click Go Advanced, select [SOLVED] from the Prefix dropdown,
then click Save Changes.
Regards, John
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks