Vba 从web导入数据后在excel中重命名工作表
我想使用vba中的以下代码下载我们证券交易所的每日价格。虽然代码有效,但我似乎无法将图纸重命名为获得价目表的相应日期Vba 从web导入数据后在excel中重命名工作表,vba,excel,Vba,Excel,我想使用vba中的以下代码下载我们证券交易所的每日价格。虽然代码有效,但我似乎无法将图纸重命名为获得价目表的相应日期 Dim DownloadDay As Date DownloadDay = #3/4/2014# Do While DownloadDay < #4/4/2014# ActiveWorkbook.Worksheets.Add Call website(Format(DownloadDay, "YYYYMMDD")) 'INCREMENT THE DAY She
Dim DownloadDay As Date
DownloadDay = #3/4/2014#
Do While DownloadDay < #4/4/2014#
ActiveWorkbook.Worksheets.Add
Call website(Format(DownloadDay, "YYYYMMDD"))
'INCREMENT THE DAY
Sheets.Add.Name = "DownloadDay"
DownloadDay = DownloadDay + 1
Loop
End Sub
Sub website(sDate As String)
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://live.mystocks.co.ke/price_list/" & DownloadDay & "/", Destination:=Range("$A$1"))
.Name = DownloadDay
'To rename each work sheet with the corresponding day'
.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
End With
End Sub
Dim下载日期为日期
下载日=#3/4/2014#
下载时做些什么2014年4月4日#
ActiveWorkbook.Worksheets.Add
呼叫网站(格式(下载日,“YYYYMMDD”))
"日增,
Sheets.Add.Name=“下载日”
下载日=下载日+1
环
端接头
子网站(sDate作为字符串)
使用ActiveSheet.QueryTables.Add(连接:=_
“网址;http://live.mystocks.co.ke/price_list/下载日(&DownloadDay&“/”,目的地:=范围($A$1))
.Name=下载日
'用相应的日期重命名每个工作表'
.FieldNames=True
.rowNumber=False
.FillAdjacentFormulas=False
.PreserveFormatting=True
.refreshinfoleopen=False
.BackgroundQuery=True
.RefreshStyle=xlInsertDeleteCells
.SavePassword=False
.SaveData=True
.AdjustColumnWidth=True
.RefreshPeriod=0
.WebSelectionType=xlTables
.WebFormatting=xlWebFormattingNone
.WebPreFormattedTextToColumns=True
.WebConsecutiveDelimiterSong=True
.WebSingleBlockTextImport=False
.WebDisableDateRecognition=False
.WebDisableRedirections=False
.Refresh BackgroundQuery:=False
以
端接头
这行VBA将设置工作表的名称:
Sheets("Sheet2").Name = "NewName"
但是,不能在名称中使用“/”字符,并且变量设置为日期而不是字符串
试试这个
.name = CSTR(FORMAT(DownloadDay,"YYYYMMMDD"))