Tuesday, 3 September 2013

Excel VBA, refresh data on opening if not refreshed today already

Excel VBA, refresh data on opening if not refreshed today already

I have an excel spreadsheet that uses pivot tables.
Currently I have a hyperlink to refresh the data which is new each day.
I would like to develop a method of refreshing the data on opening the
Excel file, but not it it has already been updated today.
Is this possible using VBA?
My current code is...
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Range.Address = "$A$1" Then
MsgBox "Your data will now be updated. This may take a
moment..."
ActiveWorkbook.RefreshAll
Sheet1.Range("A2").Value = DateTime.Now
Exit Sub
End If
End Sub
Thanks in advance.

No comments:

Post a Comment