2013-02-07 46 views
0

我不知道如何從網站導入數據,我需要從2012年7月1日至今。任何想法傢伙?我不知道如何做到這一點,因爲URL更改。我想從2012年7月到現在導入所有數據,所以我可以通過網頁的html源代碼來完成這項工作嗎?使用VBA代碼從excel導入數據的網頁不同日期使用VBA代碼

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

如果URL,當你按日期篩選你能不能只使用新的URL在您的連接變化? – Rick

+0

至少告訴我們這個URL每天的格式!它應該只是一個動態生成URL的問題。你想每天自動繼續嗎? –

+0

它需要這樣的:http://www.epexspot.com/en/market-data/intraday/intraday-table/2013-02-06/FR隨着日,月,年的變化而變化。我想從2012年1月7日直到現在導入所有的數據。是的,理想的情況下,我會自動從2012年1月7日開始做這件事..任何想法@ElectricLlama tnx您的評論 – EyeShield21

回答

1

下一個迭代:現在,您可以撥打DownloadPeriod並應該刪除數據上的一些每天一個工作表在2012年請測試一月,我們可以去到的代碼下一次迭代。

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 

末次

+0

Tnx您的評論,我做了一個很少有關於url的更正,當你給出日期時,它真的會導入表格,我的意思是具體的日期,這很好,但我想導入一個特定的列(小時和平均重量,而不是整個表格) 。你有什麼想法,我該如何做到這一點??我的意思是,當我給我輸入日期我想導入時間列和重量平均值列彼此旁邊。如果你有任何想法,這將是至關重要的@ElectricLlama – EyeShield21

+0

epexspot需要提供一個特殊的URL來檢索一列。您是否仍然有興趣在不同的日子檢索一系列數據? –

+0

是的,如果你有任何想法,我將不勝感激 – EyeShield21