When the workbook opens, the date in T1 is not changing: Private Sub WorkbookOpen() Dim…
- User
When the workbook opens, the date in T1 is not changing: Private Sub Workbook_Open()
Dim backupPath As String Dim popup As Object Dim message As String Dim duration As Integer Dim todaysDate As Date
If ThisWorkbook.Worksheets("Incidents").Range("T1").Value <> todaysDate Then On Error GoTo ErrorExit ' Implement error handling Application.EnableEvents = False
backupPath = ThisWorkbook.Path & "\IncidentReportsBckup\" backupPath = backupPath & "IncidentReports_" & Format(Now, "ddmmyy_hhmmss") & ".xlsb" Me.SaveCopyAs backupPath MsgBox "IncidentReports Daily Backup Saved", vbInformation, "BACKUP" ' Write today’s date to Range K1 ThisWorkbook.Worksheets("Incidents").Unprotect Password:="edit" ThisWorkbook.Worksheets("Incidents").Range("T1").Value = todaysDate ThisWorkbook.Worksheets("Incidents").Protect Password:="edit" - Assistant
It looks like the issue in your code is that you never actually set the
todaysDatevariable to the current date before you compare it with the value in cellT1. The variabletodaysDateshould be set to today's date using the function. Here's your corrected code: