返回列表 上一主題 發帖

上網抓股票資料

上網抓股票資料

請教各位大大:
有個VBA程式資料抓不下來
請各位大大幫忙查看哪裡有問題
謝謝
Private Sub CommandButton1_Click()
Dim po As Integer        '宣告PO為整數

lR = Range("A2").End(xlDown).Row
Rows(lR + 1 & ":400").Select       'a欄空白以下全刪除
Selection.Delete shift:=xlUp


LRA = Range("C2").End(xlDown).Row
For i = 3 To LRA
If Cells(i, 5) <> "" Then
ValueSno = "$A$" & i
Linkss = "URL;https://tw.stock.yahoo.com/q/q?s=" & Cells(i, 1)
        
po = lR - 5 + (7 * (i - 2)) '定抓取資料表格迴圈
With ActiveSheet.QueryTables.Add(Connection:= _
Linkss, Destination:=Sheets("工作表1").Range("b" & po))
      .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 = "6"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
        .Name = .ResultRange.Cells(3, 1)
    End With   
Range("A" & po + 2) = Cells(i, 1)
Cells(i, 2) = "=vlookup(" & Cells(i, 1) & ",$A$16:$0$200,2,0)"
Cells(i, 2) = Mid(Cells(i, 2), 5)
Cells(i, 7) = "=vlookup(" & Cells(i, 1) & ",$A$16:$0$200,4,0)"
End If
Next

End Sub
michael

回復 2# GBKEE
感謝大大抽空幫我看
但是好像也沒有辦法抓下資料
附個壓縮檔再麻煩大大幫我看一下

股票.rar (12 KB)

michael

TOP

版主:
不勝感謝版主不斷的幫我修改
但是我只抓下第一個股票就卡在
Cells(i, 2) = Mid(Cells(i, 2), 5)
它顯示
執行階段錯誤'13
型態不符
能否請版主在幫我看一下那裡還有問題
謝謝
michael

TOP

回復 9# c_c_lai

c_c_lai大大 :
感謝出手指導
因是新手要消化需要一點時間
經過修改
現在跑起來可以了
如有還問題
請大大幫忙
謝謝各位大大
michael

TOP

        靜思自在 : 君子如水,隨方就圓,無處不自在。
返回列表 上一主題