簡體   English   中英

從網絡導入數據后,在Excel中重命名工作表

[英]Getting Worksheets renamed in excel after importing data from the web

我想使用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

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

VBA的這一行將設置工作表的名稱:

Sheets("Sheet2").Name = "NewName"

您不能在名稱中使用“ /”字符,並且變量設置為日期而不是字符串。

嘗試這個。

.name = CSTR(FORMAT(DownloadDay,"YYYYMMMDD"))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM