2013-02-07 47 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