我不知道如何从网站导入数据,自2012年7月1日至今,我需要这样做。任何想法的家伙?自url更改后我不知道该怎么做。我想从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
答案 0 :(得分: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
End Sub