- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
3#
發表於 2013-9-24 15:04
| 只看該作者
回復 1# gelai01000001
下載3年歷史股價的資料- Option Explicit
- Sub 鉅亨網_歷史行情()
- Dim Sh As Worksheet, Code As String, d_Start As String, d_End As String
- Dim A As Object, i As Integer, c As Integer, T As Date
- Code = InputBox("輸入股票代號 : ", "股票代號", 2303)
- d_End = InputBox("輸入結束日期 : ", "結束日期", Date)
- If Len(Code) <= 3 Or Not IsDate(d_End) Then Exit Sub
- Set Sh = ActiveSheet
- With Sh
- .UsedRange.Clear
- .[a1] = Code
- .[b1] = DateAdd("yyyy", -3, d_End) '下載3年歷史股價的資料
- .[C1] = d_End
- Code = .[a1]
- d_Start = Format(.[b1], "yyyy/mm/dd")
- d_End = Format(.[C1], "yyyy/mm/dd")
- End With
- With CreateObject("InternetExplorer.application")
- .Navigate "http://www.cnyes.com/twstock/ps_historyprice/" & Code & ".htm"
- '.Visible = True
- Application.StatusBar = Code & " 歷史行情 等候中..."
- Do While .Busy Or .ReadyState <> 4
- DoEvents
- Loop
- Set A = .Document.getelementsbytagname("input")
- A(5).Value = d_Start
- A(6).Value = d_End
- A(7).Click
- T = Time
- Do
- DoEvents
- Loop Until Time > T + #12:00:08 AM#
- Set A = .Document.getelementsbytagname("table")(1)
- Application.StatusBar = Code & " 歷史行情 下載中..."
- Cells(2, 1) = .Document.getelementsbytagname("span")(79).innertext
- For i = 0 To A.Rows.Length - 1
- For c = 0 To A.Rows(i).Cells.Length - 1
- Sh.Cells(i + 3, c + 1) = A.Rows(i).Cells(c).innertext
- Next
- Next
- .Quit
- End With
- Application.StatusBar = Code & " 歷史行情 " & Application.Text(Time - T, "[S] 秒") & " 下載完成"
- MsgBox "OK"
- Application.StatusBar = False
- End Sub
複製代碼 |
|