I’m using Excel 2010 to link a table to a XML file on my server. I’d like to distribute the Excel file to a group of people and have it updated every time the XML file is updated on the server.
In Excel, I’m pulling the data using “Data”, “From Web” and then I type in the path of the XML file.
Excel then builds a table with all the data but if the XML file is updated on the server, the data remains static, even if I click “Refresh” or “Refresh XML data” on the table.
It should be able to download new data including new columns to the table, if any.
Is there a way to do this?
I am not an expert in VBA , here what I will do
1. Refreshing when opening an Excel file , That can be done by
Sub RefreshData()
ActiveWorkbook.RefreshAll
' or you can give specific workbook and worksheet identification
End Sub
Private Sub Workbook_Open()
'Call Refresh Data Subroutine when opening file
RefreshData
end sub
-
You can use worksheet activate event handler if you have multiple worksheet in a file.
Private Sub Worksheet_Activate()
‘Call Refresh Data Subroutine when opening file
RefreshData
End Sub -
Updating MSexcel as soon as server gets update , doesn’t make sense as data will be available for view only after file gets open , however if your macro is been used for live monitoring and kept open 24 hours then instead of sending a event from server and catching in VBA , I suggest implement polling every day/hour/minute/second ( call refresh at poll interval) depending upon your refresh requirement criticality.
Dim TimeToRun
Sub auto_open()
Call Schedulerefresh
End SubSub Schedulerefersh()
TimeToRun = Now + TimeValue(“00:00:10”)Application.OnTime TimeToRun, "XMLRefersh"
End Sub
Sub XMLRefresh()
‘Call Refresh Data Subroutine when opening file
RefreshData
Call ScheduleRefresh
End SubSub auto_close()
On Error Resume Next
Application.OnTime TimeToRun, “XMLRefresh”, , False
End Sub