MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Detecting Changes in a Worksheet

Posted by Craig on December 28, 2001 10:27 AM

If an Addition and/or Change is made in an Excel worksheet, can you detect it with code when the file is closed?

Posted by Dank on December 28, 2001 11:27 AM

Yes, you can. Check the Saved property of the workbook before closing. E.g. place this code in the workbook's code module:-

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If ThisWorkbook.Saved = True Then
MsgBox "You must save before closing..."
'Cancel the closing of the workbook
Cancel = True
End If
End Sub

Hope it helps,