返回列表 上一主題 發帖

[發問] 使用陣列代碼帶入股票

回復 1# s13983037
試試看
  1. Option Explicit
  2. Private Sub CommandButton1_Click()
  3.     Dim E As Object, i As Integer, ii As Integer, k As Integer
  4.     Dim StockArr(), A As Variant, Sh As Worksheet
  5.     StockArr = Array(9946, 2330, 2317, 5522) '等等的股票
  6.     Set Sh = ActiveSheet
  7.     Sh.UsedRange.Clear
  8.     With CreateObject("InternetExplorer.Application")
  9.         .Visible = True
  10.         k = 1
  11.         For Each A In StockArr
  12.             .Navigate "http://www.cnyes.com/twstock/intro/" & A & ".htm"
  13.             Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
  14.             Sh.Cells(k, 1) = Split(.document.Title, "_")(0)  '股票:名稱代號
  15.             Set E = .document.getElementsByTAGName("TABLE")(4)
  16.             For i = 0 To E.Rows.Length - 1
  17.                 k = k + 1
  18.                 For ii = 0 To E.Rows(i).Cells.Length - 1
  19.                     Sh.Cells(k, ii + 1) = E.Rows(i).Cells(ii).INNERTEXT
  20.                 Next
  21.             Next
  22.             '**************************************************************
  23.            .Navigate "http://pchome.megatime.com.tw/stock/sid" & A & ".html"
  24.             Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
  25.             Set E = .document.getElementsByTAGName("TABLE")(4)
  26.             For i = 0 To E.Rows.Length - 1
  27.                 k = k + 1
  28.                 For ii = 0 To E.Rows(i).Cells.Length - 1
  29.                     Sh.Cells(k, ii + 1) = E.Rows(i).Cells(ii).INNERTEXT
  30.                 Next
  31.             Next
  32.             k = k + 2
  33.         Next
  34.         .Quit        '關閉網頁
  35.     End With
  36.     With Sh.Range("a:a")
  37.         .Replace "相關權証", "=500/0"   '產生錯誤的公式
  38.         If Not .Find("#DIV/0!", LookIn:=xlValues) Is Nothing Then
  39.             .SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Delete
  40.         End If
  41.     End With
  42. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 4# s13983037

請自行帶入你的程式
  1. '**************************************************************
  2.             .Navigate "http://jsjustweb.jihsun.com.tw/z/zc/zcx/zcx_" & A & ".asp.htm"
  3.             Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
  4.             Set E = .document.getElementsByTAGName("TABLE")(12)
  5.             For i = 10 To E.Rows.Length - 1   '*** 挑選你要的資料***
  6.                 k = k + 1
  7.                 For ii = 0 To E.Rows(i).Cells.Length - 1
  8.                 Debug.Print i, E.Rows(i).Cells(ii).INNERTEXT  '可得知你要的資料 在哪一個Rows中
  9.                     Sh.Cells(k, ii + 1) = E.Rows(i).Cells(ii).INNERTEXT
  10.                 Next
  11.             Next
  12.             k = k + 2
  13.         Next
  14.         .Quit        '關閉網頁
  15.     End With
  16.     '/////// 有挑選你要的資料這段的程式碼可以不要了
  17.     With Sh.Range("a:a")
  18.         .Replace "相關權証", "=500/0"   '產生錯誤的公式
  19.         If Not .Find("#DIV/0!", LookIn:=xlValues) Is Nothing Then
  20.             .SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Delete
  21.         End If
  22.     End With
  23.     '////////////////////////////////////////////////
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 口說一句好話,如口出蓮花;口說一句壞話如口吐毒蛇。
返回列表 上一主題