我想到这个网站:http://www.shfe.com.cn/dailydata/kx/kx20111209里获取表格数据然后输入到EXCEL中,但是问题来了,如果下面的代码中URL的地址是上述地址的话获取正常,这个网站的数据每天都会更新,所以我想的是根据每天的时间获取新的数据。比如http://www.shfe.com.cn/dailydata/kx/kx20111208是12月8日的数据,http://www.shfe.com.cn/dailydata/kx/kx20111209是12月9日的数据。所以我定义了个DATES变量接收当前年月日的数据,Dim DATES As String
DATES = Format(Date, "yyyymmdd ") ,但是这样程序就会报错,说404错误,获取不到这个地址。请问下是什么情况谢谢拉
我得程序代码是:
- VB code
Private Sub CommandButton3_Click() Dim DATES As String DATES = Format(Date, "yyyymmdd ") With Worksheets("上海期货").QueryTables.Add(Connection:= _ "URL;http://www.shfe.com.cn/dailydata/kx/kx" + DATES + "" _ , Destination:=Worksheets("上海期货").Range("A1")) .Name = _ "上海期货" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = False .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 ' .WebSelectionType = xlSpecifiedTables WebSelectionType = xlAllTables .WebFormatting = xlWebFormattingRTF .RefreshStyle = xlOverwriteCells ' .WebTables = "13" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=True End With End Sub
问题来了。
------解决方案--------------------------------------------------------
请将
DATES = Format(Date, "yyyymmdd ")
改成
DATES = Format(Date, "yyyymmdd")