返回列表 上一主題 發帖

[發問] 如何可以指定日期後下載資料

本帖最後由 GBKEE 於 2013-12-9 15:53 編輯

回復 1# pupai
每一網頁的元素會有所不同.
  1. Option Explicit
  2. Sub 外資及陸資買賣超彙總表()
  3.     Dim URL As String, xDate As Date
  4.     xDate = Format(Date-1, "E/M/D")
  5.     URL = "URL;http://www.twse.com.tw/ch/trading/fund/TWT38U/TWT38U.php?qdate=" & xDate
  6.     With ActiveSheet.QueryTables.Add(Connection:=URL, Destination:=ActiveSheet.Range("a1"))
  7.         .WebSelectionType = xlSpecifiedTables
  8.         .WebFormatting = xlWebFormattingNone
  9.         .WebTables = "5"
  10.         .WebPreFormattedTextToColumns = True
  11.         .WebConsecutiveDelimitersAsOne = True
  12.         .WebSingleBlockTextImport = False
  13.         .WebDisableDateRecognition = False
  14.         .WebDisableRedirections = False
  15.         .Refresh BackgroundQuery:=False
  16.     End With
  17. End Sub
  18. Sub 投信買賣超彙總表()
  19.     Dim URL As String, xDate As Date
  20.     xDate = Format(Date-1, "E/M/D")
  21.     URL = "URL;http://www.twse.com.tw/ch/trading/fund/TWT44U/TWT44U.php?qdate=" & xDate
  22.     With ActiveSheet.QueryTables.Add(Connection:=URL, Destination:=ActiveSheet.Range("D4"))
  23.         .Connection = URL
  24.         .WebSelectionType = xlSpecifiedTables
  25.         .WebFormatting = xlWebFormattingNone
  26.         .WebTables = "5"
  27.         .WebPreFormattedTextToColumns = True
  28.         .WebConsecutiveDelimitersAsOne = True
  29.         .WebSingleBlockTextImport = False
  30.         .WebDisableDateRecognition = False
  31.         .WebDisableRedirections = False
  32.         .Refresh BackgroundQuery:=False
  33.     End With
  34. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 GBKEE 於 2013-12-9 18:32 編輯

回復 3# pupai
  1. Option Explicit
  2. Sub 外資及陸資買賣超彙總表()
  3.     Dim URL As String, xDate As Date
  4.     xDate = Date - 1   '經查: 外資及陸資買賣超彙總表 提供前一營業日的資料
  5. ReDate:
  6.     URL = "URL;http://www.twse.com.tw/ch/trading/fund/TWT38U/TWT38U.php?qdate=" & Format(xDate, "E/M/D")
  7.     With ActiveSheet.QueryTables.Add(Connection:=URL, Destination:=ActiveSheet.Range("a1"))
  8.         .WebSelectionType = xlSpecifiedTables
  9.         .WebFormatting = xlWebFormattingNone
  10.         .WebTables = "5"
  11.         .WebPreFormattedTextToColumns = True
  12.         .WebConsecutiveDelimitersAsOne = True
  13.         .WebSingleBlockTextImport = False
  14.         .WebDisableDateRecognition = False
  15.         .WebDisableRedirections = False
  16.         .Refresh BackgroundQuery:=False
  17.         If Application.CountA(.ResultRange) = 0 Then '非營業日,沒有資料.
  18.             xDate = xDate - 1                        '往後退一日
  19.             GoTo ReDate
  20.         End If
  21.     End With
  22. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 君子立恆志,小人恆立志。
返回列表 上一主題