- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
3#
發表於 2016-2-14 09:34
| 只看該作者
回復 1# espionage
Application.Wait Now + #12:00:10 AM# '在程式中'等候10秒
等候10秒 不一定等的到- Option Explicit
- Sub Ex()
- Dim mysearchrange As Integer, mysearchdate As String, xR As Integer, xC As Integer
- Dim xTable As Object, A As Object, C As Object, myopt As Object
- For mysearchrange = 2 To 3 '設定要尋找的日期
- mysearchdate = Sheets("總表").Cells(mysearchrange, 5) '日期格式 yyyy-mm-dd
- With CreateObject("InternetExplorer.Application")
- .Visible = True
- .Navigate "http://www.cnyes.com/twstock/a_technical2.aspx"
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- With .Document
- '--------------------輸入要查詢的股票市場
- For Each A In .getElementsByTagName("SELECT")
- If A.Name = "ctl00$ContentPlaceHolder1$D1" Then
- For Each myopt In A.Options
- If myopt.innertext = "集中市場" Then
- myopt.Selected = True
- GoTo SeLe1
- End If
- Next
- End If
- Next
- SeLe1: '-------------------輸入要查詢的日期範圍
- For Each A In .getElementsByTagName("SELECT")
- If A.Name = "ctl00$ContentPlaceHolder1$D3" Then
- For Each myopt In A.Options
- If myopt.innertext = mysearchdate Then
- myopt.Selected = True
- A.fireEvent ("onchange")
- GoTo SeLe2
- End If
- Next
- End If
- Next
- SeLe2:
- End With
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- Do Until InStr(.Document.getElementByid("ctl00_ContentPlaceHolder1_UpdatePanel1").innertext, mysearchdate)
- '等候下載:指訂日期資料
- DoEvents
- Loop
- Set xTable = .Document.getElementsByTagName("TABLE")(1)
- ActiveSheet.UsedRange.Clear
- For Each A In xTable.Rows 'Table的Rows物件集合
- xR = xR + 1 '下一列號
- xC = 1
- For Each C In A.Cells 'Table的Row物件的Cells物件集合
- Cells(xR, xC) = C.innertext
- xC = xC + 1
- Next
- Next
- End With
- Next
- End Sub
複製代碼 |
|