问题
i don't know how to import data from a web site ,which i need to do it since 1st of July 2012 until present. Any ideas guys?? I don't know how to do it since url changes. I want to import all the data since July 2012 until now so can i do it through html source of the web page?
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
回答1:
Next iteration: You can now call DownloadPeriod and it should drop the data on to a number one worksheets per day in January 2012. Please test and we can go on to the next iteration of code.
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
来源:https://stackoverflow.com/questions/14762570/importing-data-from-web-page-with-diffrent-dates-in-excel-using-vba-code