我正在使用 Excel 2010 将表链接到服务器上的 XML 文件。我想将 Excel 文件分发给一群人,并在每次在服务器上更新 XML 文件时更新它。
在 Excel 中,我使用“Data”、“From Web”提取数据,然后输入 XML 文件的路径。
Excel 然后用所有数据构建一个表,但如果 XML 文件在服务器上更新,数据保持静态,即使我单击表上的“刷新”或“刷新 XML 数据”。
它应该能够将包括新列在内的新数据下载到表中(如果有的话)。
有没有办法做到这一点?
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 Sub
Sub 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 Sub
Sub auto_close() On Error Resume Next Application.OnTime TimeToRun, "XMLRefresh", , False End Sub