返回列表 上一主題 發帖

[發問] 交易進行中的1分鐘股價紀錄

本帖最後由 GBKEE 於 2018-9-3 16:27 編輯

回復 1# Scott090
沒實際執行整天行情過,請自行測試
  1. Option Explicit
  2. Sub EX()  '檔案開啟時請指定執行此程式
  3.     If Time < #9:00:00 AM# Then
  4.         Application.OnTime #9:00:00 AM#, "Ex_yahoo"
  5.     ElseIf Time <= #2:30:00 PM# Then
  6.         Ex_yahoo
  7.     End If
  8. End Sub
  9. Sub Ex_yahoo()
  10.     Dim oXmlhttp As Object, oHtmldoc As Object, E As Object
  11.     Dim R As Integer, RR As Integer, C As Integer, xTime As Double
  12.     If Time <= #2:30:00 PM# Then Application.OnTime #12:05:00 AM#, "Ex_yahoo"   '5分鐘後再度執行
  13.     Set oXmlhttp = CreateObject("msxml2.xmlhttp")
  14.     Set oHtmldoc = CreateObject("htmlfile")
  15.     With oXmlhttp
  16.         .Open "Get", "https://tw.stock.yahoo.com/q/ts?s=2330&t=50", False
  17.         .Send
  18.         oHtmldoc.write .responseText
  19.     End With
  20.     With Sheets("工作表1")
  21.         Set E = oHtmldoc.all.tags("table")(6)
  22.         If .[a1] <> E.Rows(0).Cells(0).innertext & "-" & E.Rows(0).Cells(1).innertext Then
  23.             .Cells.Clear
  24.             .[a1] = E.Rows(0).Cells(0).innertext & "-" & E.Rows(0).Cells(1).innertext
  25.         End If
  26.         Set E = oHtmldoc.all.tags("table")(7)
  27.         If .[a2] = "" Then
  28.             For C = 0 To E.Rows(0).Cells.Length - 1
  29.                 .Cells(2, C + 1) = E.Rows(0).Cells(C).innertext
  30.             Next
  31.         End If
  32.         For R = E.Rows.Length - 1 To 1 Step -1
  33.             xTime = TimeValue(E.Rows(R).Cells(0).innertext)
  34.             If IsError(Application.Match(xTime, .[A:A], 0)) Then
  35.                 RR = Application.CountA(.[A:A]) + 1
  36.                 For C = 0 To E.Rows(R).Cells.Length - 1
  37.                 .Cells(RR, C + 1) = E.Rows(R).Cells(C).innertext
  38.                 Next
  39.             End If
  40.         Next
  41.     End With
  42.     Set oXmlhttp = Nothing
  43.     Set oHtmldoc = Nothing
  44.    
  45. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 時時好心就是時時好日。
返回列表 上一主題