練習了一個excel巨集 從台灣證券下載資料下來,
但會有幾個問題
1. 若我i 從 10到18, 跑到12將會出現錯誤 錯誤行為下:
.Refresh BackgroundQuery:=False
請問這是因為週末沒有網頁的關係? 有沒有辦法克服?
2. 因為網址月分跟日期十位數以下皆是以01, 02, ....,08,09表示
並非以1,2,3...表示
這樣我如何利用迴圈寫出i= 01, 02,....,08, 09, 10...,30
迴圈 i 的條件有什麼辦法可以克服這個問題?
巨集編碼如下:
Sub Macro1()
For i = 10 To 18
ActiveWorkbook.Worksheets.Add
ActiveSheet.Name = i
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.twse.com.tw/ch/trading/exchange/BFIAMU/genpage/Report201310/201310" & i & "_F3_1_5.php" _
, Destination:=Range("$A$1"))
.Name = "201310" & i & "_F3_1_5"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "8"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Next i
End Sub
This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers. Five Filters recommends: