返回列表 上一主題 發帖

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

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

您好
我希望程式可以依照我想要的日期下載當天資料
可以幫我指導修改
謝謝!!
  1. Option Explicit
  2. Sub EX()
  3.    
  4.    
  5. Dim URL As String, xCo_Id As String, xSyear As String, xSseason As String
  6.       
  7.        xCo_Id = Range("B1").Value
  8.        xSyear = Range("B2").Value
  9.        xSseason = Range("B3").Value
  10.       
  11. 'xCo_Id = "[" & """年度""" & "," & """102年""" & "]"
  12. '要求輸入網頁的參數:年度
  13. 'xSyear = "[" & """月份""" & "," & """月 """ & "]"
  14. 'Format(Date, "e")->中華民國的月份
  15. 'xSseason = "[" & """日""" & "," & """日期""" & "]"
  16. 'Format(Date, "q")->當年度的日期


  17. '外資及陸資買賣超彙總表
  18. URL = "URL;http://www.twse.com.tw/ch/trading/fund/TWT38U/TWT38U.php?step=1&CO_ID=" & xCo_Id & "&SYEAR=" & xSyear & "&SSEASON=" & xSseason & "&REPORT_ID=C"
  19.     With ActiveSheet.QueryTables.Add(Connection:=URL, Destination:=Range("D4"))
  20.         .AdjustColumnWidth = False                   '自動調整欄寬
  21.         .WebSelectionType = xlSpecifiedTables
  22.         .WebFormatting = xlWebFormattingNone
  23.         .WebTables = "2"
  24.         .WebPreFormattedTextToColumns = True
  25.         .WebConsecutiveDelimitersAsOne = True
  26.         .WebSingleBlockTextImport = False
  27.         .WebDisableDateRecognition = False
  28.         .WebDisableRedirections = False
  29.         .Refresh BackgroundQuery:=False
  30. End With

  31. '投信買賣超彙總表
  32. URL = "URL;http://www.twse.com.tw/ch/trading/fund/TWT44U/TWT44U.php?step=1&CO_ID=" & xCo_Id & "&SYEAR=" & xSyear & "&SSEASON=" & xSseason & "&REPORT_ID=C"
  33.     With ActiveSheet.QueryTables.Add(Connection:=URL, Destination:=Range("K5"))
  34.         
  35.         .AdjustColumnWidth = False                   '自動調整欄寬
  36.         .WebSelectionType = xlSpecifiedTables
  37.         .WebFormatting = xlWebFormattingNone
  38.         .WebTables = "2"
  39.         .WebPreFormattedTextToColumns = True
  40.         .WebConsecutiveDelimitersAsOne = True
  41.         .WebSingleBlockTextImport = False
  42.         .WebDisableDateRecognition = False
  43.         .WebDisableRedirections = False
  44.         .Refresh BackgroundQuery:=False
  45.         
  46.     End With

  47.       
  48. End Sub
複製代碼

回復 2# GBKEE


    版主
請教為什麼程式跑不出東西
謝謝

TOP

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

回復 4# GBKEE


感謝   
不懂的很多 但學到也很多
謝謝!!

TOP

        靜思自在 : 人生沒有所有權,只有生命的使用權。
返回列表 上一主題