返回列表 上一主題 發帖

[發問] 股票歷史價格表

回復 2# Scott090

幫大大補充一下,
1.44~51行那邊應該可以用document.all(name)取代會比較簡單
2.可以透過修改
https://www.cnyes.com/twstock/ps_historyprice.aspx?code=2330&ctl00$ContentPlaceHolder1$startText=2001/10/05&ctl00$ContentPlaceHolder1$endText=2018/01/09
然後用外部匯入,會比較快,也比較簡單
個人小小想法,參考一下
Excel VBA網頁資料收集教學:
http://forum.twbts.com/thread-20848-1-1.html

TOP

回復 5# Scott090


  我的是按F1之後會上網找說明

另外我的想法是用QueryTable的方式
  1. Sub 股價()

  2. [A10].CurrentRegion.Clear

  3. stockno = [B3]
  4. mydate1 = Format([B4], "YYYY/MM/DD")
  5. mydate2 = Format([B5], "YYYY/MM/DD")
  6. myurl = "https://www.cnyes.com/twstock/ps_historyprice.aspx?code=" & stockno & "&ctl00$ContentPlaceHolder1$startText=" & mydate1 & "&ctl00$ContentPlaceHolder1$endText=" & mydate2

  7. With ActiveSheet.QueryTables.Add(Connection:= _
  8.         "URL;" & myurl _
  9.         , Destination:=Range("$A$10"))
  10.         .RowNumbers = False
  11.         .FillAdjacentFormulas = False
  12.         .PreserveFormatting = False
  13.         .RefreshOnFileOpen = False
  14.         .BackgroundQuery = False
  15.         .RefreshStyle = xlOverwriteCells
  16.         .SavePassword = False
  17.         .SaveData = True
  18.         .AdjustColumnWidth = False
  19.         .RefreshPeriod = 0
  20.         .WebSelectionType = xlSpecifiedTables
  21.         .WebFormatting = xlWebFormattingNone
  22.         .WebTables = "1"
  23.         .WebPreFormattedTextToColumns = True
  24.         .WebConsecutiveDelimitersAsOne = True
  25.         .WebSingleBlockTextImport = False
  26.         .WebDisableDateRecognition = False
  27.         .WebDisableRedirections = False
  28.         .Refresh BackgroundQuery:=False
  29.         .Delete
  30.     End With
  31. End Sub
複製代碼
Excel VBA網頁資料收集教學:
http://forum.twbts.com/thread-20848-1-1.html

TOP

回復 8# GBKEE


   我記得會造成不一樣是因為如果輸入日期剛好碰到假日,那資料會以下一個工作日開始,例如輸入20180128(日),那就會抓到從20180129(一)開始的資料
Excel VBA網頁資料收集教學:
http://forum.twbts.com/thread-20848-1-1.html

TOP

        靜思自在 : 原諒別人就是善待自己。
返回列表 上一主題