excel - 导入 html 网页表格
问题描述
我想使用 VBA 从网页导入数据,但出现 1004 错误。这是我使用的代码:
Sub QueryStarter()
'This is an adaptation from some code found at:
'https://stackoverflow.com/questions/19306832/web-query-vba-refresh
Dim url As String
url = "URL;https://www.xe.com/currencytables/?from=USD&date=2020-12-02"
With Worksheets("Sheet1").QueryTables.Add(Connection:=url, Destination:=Worksheets("Sheet1").Range("A1"))
.Name = "My Query"
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False <-----this line gives me the error
End With
End Sub
我需要从该网站导入表格。如果有人有使用 VBA 查询的经验,但没有使用 IE 应用程序,可能使用 HTML。如果您能帮助我,我将不胜感激。