返回列表 上一主題 發帖

Object資料怎麼轉到Worksheet!

回復 1# chlungi
試試看




  1. Sub 股市資料網頁()
  2.     Dim Rng(1) As Range, i As Integer
  3.     With ActiveSheet
  4.         Set Rng(0) = .[C1]          '股票代號輸入處
  5.         Set Rng(1) = .[B4]          '股票數據存放起始點
  6.     End With
  7.     With CreateObject("InternetExplorer.Application")
  8.         .Navigate ("http://tw.stock.yahoo.com/q/q?s=" & Rng(0))
  9.         Do While .Busy = True
  10.         Loop
  11.         DoEvents
  12.         For i = 0 To .Document.all.Length - 1
  13.             If .Document.all(i).tagName = "TD" And Len(.Document.all(i).innerText) > 3 Then
  14.                
  15.                 If .Document.all(i).innerText Like "****/**/**" Then Rng(0).Offset(1, -1) = .Document.all(i).innerText   '取得資料的日期
  16.                         
  17.                 If .Document.all(i).innerText Like Rng(0) & "*" Then
  18.                     Rng(1).Value = Mid(.Document.all(i).innerText, 1, InStr(.Document.all(i).innerText, "加") - 2)  '取得股票代號名稱
  19.                     Set Rng(1) = Rng(1).Offset(, 1)                   '設定下個位址
  20.                 ElseIf Len(.Document.all(i).innerText) <= 5 Then
  21.                     Rng(1).Value = .Document.all(i).innerText          '取得股票數據
  22.                     Set Rng(1) = Rng(1).Offset(, 1)                    '設定下個位址
  23.             End If
  24.             End If
  25.         Next
  26.         .Quit
  27.     End With
  28. End Sub
複製代碼

TOP

        靜思自在 : 好事要提得起,是非要放得下,成就別人即是成就自己。
返回列表 上一主題