返回列表 上一主題 發帖

[發問] 跑到一半會卡住~~

本帖最後由 准提部林 於 2016-12-3 11:26 編輯
  1. Sub ROE_1()
  2. [ROE總表!B1].Value = String(52, "+")
  3. For i = 10 To [個股資料!B281].End(xlDown).Row
  4.     With Sheets("ROE").QueryTables.Add(Connection:= _
  5.         "URL;http://stockchannelnew.sinotrade.com.tw/z/zc/zcr/zcra/zcra_" & _
  6.         [個股資料!B1].Cells(i, 1) & ".djhtm", Destination:=[ROE!B1])
  7.         .Name = ""
  8.         .FieldNames = True
  9.         .RowNumbers = False
  10.         .FillAdjacentFormulas = False
  11.         .PreserveFormatting = True
  12.         .RefreshOnFileOpen = False
  13.         .BackgroundQuery = True
  14.         .RefreshStyle = xlInsertDeleteCells
  15.         .SavePassword = False
  16.         .SaveData = True
  17.         .AdjustColumnWidth = True
  18.         .RefreshPeriod = 0
  19.         .WebSelectionType = xlSpecifiedTables
  20.         .WebFormatting = xlWebFormattingNone
  21.         .WebTables = "1"
  22.         .WebPreFormattedTextToColumns = True
  23.         .WebConsecutiveDelimitersAsOne = True
  24.         .WebSingleBlockTextImport = False
  25.         .WebDisableDateRecognition = False
  26.         .WebDisableRedirections = False
  27.         .Refresh BackgroundQuery:=False
  28.         .Delete
  29.     End With
  30.    
  31.     Dim xF As Range, xE As Range
  32.     Set xF = [ROE!C1:C500].Find("股東權益報酬率")
  33.     If Not xF Is Nothing Then
  34.        Set xE = [ROE總表!B1].End(xlDown)(2)
  35.        xE.Select
  36.        Range(xF, xF.End(xlToRight)).Copy xE
  37.        xE(1, 0) = Sheets("個股資料").Range("C" & i)
  38.     End If
  39.     Sheets("ROE").UsedRange.Clear
  40. Next
  41. End Sub
複製代碼

TOP

回復 7# power82843


有無跳出錯誤視窗, 及錯誤行的位置,
大部份網頁為防止短時間多次的存取, 會鎖住您的ip, 所以無法完成全部匯入!

TOP

執行了三次, 都可以順利跑完:
Xl0000003.rar (288.27 KB)

TOP

回復 14# power82843


被鎖住ip, 應會出現錯誤視窗, 而且也應無法再執行, 除非清除所有的瀏覽歷程及cookie(依以前抓奇摩知識+經驗),
如果是沒有跑完到工作表的最後一筆資料, 應是 End(xlDown)的問題, 遇到空白格就停頓, 改用End(xlUp)即可,
以目前的資枓, End(xlDown) , 第368列[2301 光寶科]就是最後一筆!

For i = 10 To [個股資料!B1].Cells(Rows.Count, 1).End(xlUp).Row
則可以跑到第890列!!!

TOP

        靜思自在 : 心中常存善解、包容、感思、知足、惜福。
返回列表 上一主題