返回列表 上一主題 發帖

有辦法使用vba匯入外部web資料嗎?

回復 10# fei6999

試試看
  1. Option Explicit
  2. Sub 個別現金流量表()
  3.     Dim Sh As Worksheet
  4.     With CreateObject("InternetExplorer.Application")
  5.         .Navigate "http://mops.twse.com.tw/mops/web/t164sb05"
  6.         .Visible = True
  7.         Do While .Busy Or .readyState <> 4: DoEvents: Loop
  8.         With .Document
  9.             .getElementsByTagName("input")(38).Value = "5349"  '這裡修改 股票代號
  10.             .getElementsByTagName("input")(41).Click
  11.         End With
  12.         Do While .Busy Or .readyState <> 4: DoEvents: Loop
  13.       
  14.       '******************************
  15.        .Document.body.innerHTML = .Document.getElementsByTagName("table")(3).outerHTML
  16.         .ExecWB 17, 2       '  Select All
  17.         .ExecWB 12, 2       '  Copy selection
  18.         .Quit
  19.         End With
  20.         '****************************
  21.         Set Sh = Sheets(1)
  22.         Sh.UsedRange.Clear
  23.         With Sheets.Add(, Sheets(Sheets.Count))
  24.             .Range("A1").Select
  25.             .PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
  26.             .Range("C:D,P:P").Copy Sh.[A1]
  27.             Application.DisplayAlerts = False
  28.             .Delete
  29.             Application.DisplayAlerts = True
  30.         End With
  31.         With Sh
  32.             .Activate
  33.             .Rows("1:11").Delete
  34.             .UsedRange.EntireColumn.AutoFit
  35.         End With
  36.       
  37. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 站在半路,比走到目標更辛苦。
返回列表 上一主題