- 帖子
- 1
- 主題
- 1
- 精華
- 0
- 積分
- 2
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- 64
- 閱讀權限
- 10
- 註冊時間
- 2016-4-1
- 最後登錄
- 2016-4-4
|
各位高手專家好
小弟在使用QueryTable 時,
會在連續查詢數筆資料之後突然發生 400 的錯誤,而造成資料一直查不完,想請教是發生什麼問題呢?
程式碼和附檔如下 感謝回覆
Sub 抓取股票資料()
Dim StartTime
Dim i
Dim j
Dim StockNumber As String '股票代號
i = 2
If 確認工作表存在("Temp") <> True Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Temp"
End If
Application.ScreenUpdating = False
清除工作表 ("Temp")
Set Tempsheet = Sheets("Temp")
Do While Sheet1.Cells(i, 1) <> ""
If Sheet1.Cells(i, 2) = "" Then
StockNumber = Sheet1.Cells(i, 1)
GetCurrentPrice (StockNumber)
End If
Sheet1.Cells(i, 2) = StockName
Sheet1.Cells(i, 3) = CurrentPrice
Sheet1.Cells(i, 4) = PriceChange
Sheet1.Cells(i, 5) = StockQuantity
i = i + 1
Loop
Application.StatusBar = "股票資料抓取完成"
Application.ScreenUpdating = True
Sheet1.Activate
Sheets("Temp").Delete
End Sub
Sub GetCurrentPrice(StockNumber As String)
Dim ur As String
Application.StatusBar = "取得股票 " & StockNumber & " 股價資料中......"
ur = "https://tw.finance.yahoo.com/q/q?s=" & StockNumber
' MsgBox ur
Tempsheet.Range("A:L").Clear
With Tempsheet.QueryTables.Add(Connection:="URL;" & ur, Destination:=Tempsheet.Range("A1"))
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "6"
.Refresh BackgroundQuery:=False
.Delete
End With
StockName = Tempsheet.Cells(3, 1)
CurrentPrice = Tempsheet.Cells(3, 3)
PriceChange = Tempsheet.Cells(3, 6)
StockQuantity = Tempsheet.Cells(3, 7)
End Sub
Book1.zip (19.95 KB)
|
|