返回列表 上一主題 發帖

[發問] 如何找到正確的網址,讓EXCEL匯入WEB查詢

回復 10# bioleon69
  1. Option Explicit
  2. Sub Ex_網頁元素()
  3.     Dim i As Integer, xlTab As Object, R As Integer, C As Integer, Surl$
  4.     If Sheets("工作表1").[A1] = "" Then MsgBox "請輸入正確股票代號": Exit Sub
  5.     Surl = "http://www.cmoney.tw/finance/f00026.aspx?s=" & Sheets("工作表1").[A1]
  6.     With CreateObject("InternetExplorer.Application")
  7.         .Visible = False
  8.         .Navigate Surl
  9.         Do While .Busy Or .readyState <> 4: DoEvents: Loop
  10.             Set xlTab = .Document.ALL.tags("TABLE")(0)
  11.         If Not xlTab Is Nothing Then
  12.             With ActiveSheet
  13.                 .UsedRange.Clear
  14.                 For R = 0 To xlTab.Rows.Length - 1
  15.                     For C = 0 To xlTab.Rows(R).Cells.Length - 1
  16.                         .Cells(R + 1, C + 1) = xlTab.Rows(R).Cells(C).innertext
  17.                     Next
  18.                 Next
  19.             End With
  20.         Else
  21.             MsgBox "請輸入正確股票代號"
  22.         End If
  23.         .Quit        '關閉網頁
  24.     End With
  25. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 能付出愛心就是福,能消除煩惱就是慧。
返回列表 上一主題