我刚刚研究了如何使用excel web查询将数据导入表中。但是,每次刷新数据时,它都会覆盖顶部的最后一次更新。我是否可以使用Web查询通过在每次刷新时附加到现有表而不是覆盖并丢失旧数据来将数据加载到表中,如果是这样,该怎么办?
答案 0 :(得分:0)
`'Get onto the right sheet to copy daata
Sheets("Data").Select
'Start a loop
Dim x As Integer
Application.ScreenUpdating = False
' Set numrows = number of rows of data.
NumRows = Range("A2", Range("A2").End(xlDown)).Rows.Count
' Select cell a2.
Range("A2").Select
' Establish "For" loop to loop "numrows" number of times.
For x = 1 To NumRows
Selection.copy
'Get onto the right sheet
Sheets("APIcall").Select
'Activate the query for the specific data
'delete the query so that it can be used again and unlist it to be able to manipulate it
ActiveWorkbook.Queries("query").Unlist
ActiveWorkbook.Queries("query").Delete
'copy the info into the Data sheet into the next blank row
Sheets("APIcall").Select
Range("A2", Range("A2").End(xlToRight)).Select
Selection.copy
Sheets("Data").Select
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("APIcall").Cells.Clear
'get the next data
Sheets("Data").Select
ActiveCell.Offset(1, 0).Select
Next`
这最有可能做得更好更简单,但希望它有所帮助。