返回列表 上一主題 發帖

[發問] 使用 msXML2.xmlHTTP 取得股票交易資料

  1. Option Explicit
  2. Sub Ex()
  3.     Dim oXmlhttp As Object, oHtmldoc As Object, surl As String, E As Object, R As Integer, C As Integer
  4.     Set oXmlhttp = CreateObject("msxml2.xmlhttp")
  5.     Set oHtmldoc = CreateObject("htmlfile")
  6.     surl = "https://tw.stock.yahoo.com/q/q?s=2330"
  7.         With oXmlhttp
  8.         .Open "Get", surl, False
  9.         .Send
  10.         oHtmldoc.write .responseText
  11.     End With
  12.     ActiveSheet.Cells.Clear
  13.      With oHtmldoc
  14.         Set E = .all.tags("table")(6)
  15.         For R = 0 To E.Rows.Length - 1
  16.             For C = 0 To E.Rows(R).Cells.Length - 1
  17.                 ActiveSheet.Cells(R + 1, C + 1) = E.Rows(R).Cells(C).INNERTEXT
  18.             Next
  19.         Next
  20.         ActiveSheet.Cells(R + 1, 1) = Trim(.all.tags("table")(4).INNERTEXT)
  21.     End With
  22. End Sub
複製代碼
回復 4# Scott090
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 【停滯不前,終無所得】人都迷於尋找奇蹟,因而停滯不前;縱使時間再多、路再長,也了無用處,終無所得。
返回列表 上一主題