0

我不知道如何从网站导入数据,从 2012 年 7 月 1 日到现在我都需要这样做。有什么想法吗?由于网址更改,我不知道该怎么做。我想导入自 2012 年 7 月至今的所有数据,我可以通过网页的 html 源来导入吗?

Sub websitee()


With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;http://www.epexspot.com/en/market-data/intraday", Destination:=Range( _
    "$A$1"))
    .Name = "intraday"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .WebSelectionType = xlTables
    .WebFormatting = xlWebFormattingNone
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
     Union(Columns(3), Columns(4), Columns(5), Columns(7), Columns(8),           Columns(9)).Delete

     End With

End Sub
4

1 回答 1

2

下一次迭代:您现在可以调用 DownloadPeriod,它应该将数据放到 2012 年 1 月每天的第一工作表中。请测试,我们可以继续下一次代码迭代。

Sub DownloadDayFromUser()
     Dim sInput as String
     sInput = InputBox("Enter a date in YYYY-MM-DD format")
     Call websitee(sInput)
End Sub


Sub DownloadPeriod()
     Dim DownloadDay as Date
     DownloadDay = #1/1/2012#

     Do While DownloadDay < #1/2/2012#
         ' Create a new workbook to put the data into
         ActiveWorkBook.Worksheets.Add
         ' Call the web service for today
         Call websitee(Format(DownloadDay,"YYYY-MM-DD"))
         ' Increment the day
         DownloadDay = DownloadDay + 1
     Loop
End Sub

Sub websitee(sDate as String)


With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.epexspot.com/en/market-data/intraday/" & sDate & "/", Destination:=Range( _
"$A$1"))
.Name = "intraday"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
 Union(Columns(3), Columns(4), Columns(5), Columns(7), Columns(8),           Columns(9)).Delete

 End With

结束子

于 2013-02-08T02:57:14.807 回答