OK, what you would use is a
Workbook_Open event procedure in VBA, which is VBA code that is automatically triggered when the workbook is opened.
In order for this to work, it MUST be placed in the "
ThisWorkbook" VBA module of this workbook. If you place the VBA code in any other VBA module, it will not fire automatically.
VBA Code:
Private Sub Workbook_Open()
Dim rng As Range
Dim r As Long
' Exit if today is not the first day of the month
If Day(Date) <> 1 Then Exit Sub
' Check to see if record has already been updated (if so, exit sub)
Set rng = Sheets("Graph").Range("A:A")
If Application.WorksheetFunction.CountIf(rng, Date) > 0 Then Exit Sub
' Update Graph sheet with new record
r = Sheets("Graph").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("Graph").Range("A" & r).Value = Date
Sheets("Graph").Range("B" & r).Value = Sheets("Dashboard").Range("A5").Value
' Save changes
ActiveWorkbook.Save
' Close Excel
Application.Quit
End Sub
If you want to test it out, you can temporarily change the day number in this line to today:
VBA Code:
If Day(Date) <> 1 Then Exit Sub
i.e.
VBA Code:
If Day(Date) <> 22 Then Exit Sub
Then save, exit, and re-open the workbook, and it should copy the date and value over.
So then you would have your scheduler open this workbook on this first day of every month.
A few other things to note:
1. If you are running this from another computer (or server), make sure that VBA is enable from there so it can run when it is opened.
2. This code is always there, and will always run every time the file is opened, but it checks to see if the current day is the first of the month and if a record for today's date already exists on the "Graph" sheet. If it does, it simply exits out of the code before making any updates.
3. You probably want to schedule this to run early in the morning. If someone were to open the file up on the first BEFORE the scheduler does, it will do the update and then close Excel on them. If they then open Excel a second time, it will remain open, as the update has already been run.