I have a workbook to create a daily dashboard for our group. I have created VBA code that automatically updates a particular cell with the last save date & time when the file is saved.
I had the code in the BeforeSave event, but the problem is that if I cancel the save operation the cell date and time still gets updated. I tried using the Cancel flag and running the cell update code only if cancel is false, but it still updates the target cell with the latest date and time.
So then I put the code in the AfterSave event and it removes the cancel issue. However, after the file is saved, If I try to close the file I am prompted to save the file again.
So, I changed the code to read as follows:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
If Success Then
Application.EnableEvents = False
Sheets ("Daily Dashboard").Range.("V23").Value = "LAST SAVED " & Now
Application.EnableEvents = True
End If
End Sub
However, this still does not prevent Excel from prompting me to save the file if I try to close it.
What am I doing wrong?
I had the code in the BeforeSave event, but the problem is that if I cancel the save operation the cell date and time still gets updated. I tried using the Cancel flag and running the cell update code only if cancel is false, but it still updates the target cell with the latest date and time.
So then I put the code in the AfterSave event and it removes the cancel issue. However, after the file is saved, If I try to close the file I am prompted to save the file again.
So, I changed the code to read as follows:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
If Success Then
Application.EnableEvents = False
Sheets ("Daily Dashboard").Range.("V23").Value = "LAST SAVED " & Now
Application.EnableEvents = True
End If
End Sub
However, this still does not prevent Excel from prompting me to save the file if I try to close it.
What am I doing wrong?