将网站数据提取到Excel中

将网站数据提取到Excel中的最新答案是:

Sub FetchData() With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://www.zillow.com/homes/comps/67083361_zpid", Destination:=Range( _ "$A$1")) .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlEntirePage .WebFormatting = xlWebFormattingNone .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With End Sub 

除了我感兴趣的URL之外,它也适用于我的项目:

 URL;http://reservations.example.com/cp/reports/daily_usage.php?type=date_reservations&date=06%2F03%2F2015&date_end=&vessel=&club=6&location=135", Destination:=Range( _ "$A$1")) 

为了保护隐私,我上面使用了一个假的URL,但正如你所看到的,URL中有一个date代码。 在这种情况下,2015年6月3日由06%2F03%2F2015指定。

使用VBA,我怎样才能使URL中的datevariables,在工作表中定义?

Format()函数最有可能的。 一个疯狂的猜测会是

 Format(Range("$A$1").Value2, "mm""%2F""dd""%2F""yyyy") 

您也可以使用Day()Month()Year()函数自己重build它,还有一些玩IIf(Len(x)=2,x,0&x)
我的样本在2014-06-03给了“06%2F03%2F2014”。