I am trying to construct a piece of VBA, that will execute automatically everytime a workbook is opened. This piece of code should firstly check whether this workbook has been opened before on that specific day and secondly, if it has not been opened, it should refresh the data connections, close/save the workbook after.
I have developed the following code which I believe should work (It doesn't).
Private Sub Workbook_Open()
Dim wsSheet As Worksheet
On Error Resume Next
Set wsSheet = Sheets("book_helper")
On Error GoTo 0
If wsSheet Is Nothing Then
Sheets.Add.Name = "book_helper"
ActiveWorkbook.RefreshAll
Sheets("book_helper").Range("A1").Value = Date
ActiveWorkbook.Close savechanges:=False
Else
If Sheets("book_helper").Range("A1").Value < Date Then
ActiveWorkbook.RefreshAll
Sheets("book_helper").Range("A1").Value = Date
ActiveWorkbook.Close savechanges:=False
End If
End If
End Sub
When I open this workbook it simply does not do anything (Doesn't open and the date is not saved). Is there any better way of doing this.