使用查询从网站读取xls文件

时间:2018-01-18 19:50:50

标签: excel vba

' Builds URL for retrieval from web
CurrentDate = Sheet5.Range("A1").Text
NextDayDate = Sheet5.Range("C1").Text
URLFirstPart = "https://docs.misoenergy.org/marketreports/"
URLLastPart = "_da_pr.xls"

URLCurrentDate = URLFirstPart + CurrentDate + URLLastPart
URLNextDayDate = URLFirstPart + NextDayDate + URLLastPart

' Imports day 1 MISO data into "MISO_Day_1_Temp" tab
Set destCell = Sheet22.Range("A1")
Sheet22.Unprotect
With destCell.Parent.QueryTables.Add(Connection:="TEXT;" & URLCurrentDate, Destination:=destCell)
    .RefreshStyle = xlOverwriteCells
    .TextFileStartRow = 1
    .TextFileParseType = xlDelimited
    .TextFileCommaDelimiter = True
    .Refresh BackgroundQuery:=False
End With
destCell.Parent.QueryTables(1).Delete

我无法使用查询从网站读取xls文件。我认为问题在于连接类型。知道我应该怎么做吗?

0 个答案:

没有答案