I need to check the value of some cells in excel before the workbook is closed. If it meets the criteria it saves and closes, if not I need to escape out of the close command and display error messages. Please help
To get your code to run when the workbook is closed place your code in the Workbook_BeforeClose Event.
Something like this should do:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Cells(1,1) ="Hello World" Then
Me.Save
Else
Cancel = True
MsgBox "Please Don't Close This File"
End If
End Sub
Setting Cancel to True stops the workbook from closing.
I haven't checked the code yet, but any problems let me know.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.