- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
10#
發表於 2015-7-26 10:28
| 只看該作者
本帖最後由 GBKEE 於 2015-7-27 09:53 編輯
回復 7# lcctno
當下只發生自動開啟IE11 停在"5樓的圖1.
此程式執行後會回到VBA編輯視窗,並打開'即時運算"的視窗
請第一個STOP 之後按下F5
如停留在VBA編輯視窗,"即時運算"一直有字串出現,代表程式一直在等後IE的資料,是IE 的問題
**請耐心等候到下 一個 STOP 之後按下F5 **- Option Explicit
- Sub Ex()
- Dim E As Object, Ar(), i As Integer
- Ar = Array("http://www.yuantaetfs.com/#/RtNav/Index", "http://www.yuantaetfs.com/#/Home/Index")
- 'Ar = Array(網址:即時淨值,網址:國內指數) 網址置入陣列
- ActiveSheet.UsedRange.Clear
- For i = 0 To 1
- With CreateObject("InternetExplorer.Application")
- .Visible = True
- .Navigate Ar(i)
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- If i = 0 Then '國內指數:不需按下同意鍵
- Do
- Set E = .Document.getElementByid("Agree")
- Loop Until Not E Is Nothing
- E.Click
- End If
- .Visible = False
- Application.VBE.MainWindow.Visible = True
- Application.VBE.Windows("即時運算").Visible = True
- Stop '之後按下F5
- Do
- Do
- Set E = .Document.getElementsByTagName("TABLE")(21 + i)
- '即時淨值 第21個 "TABLE" ,'國內指數 第22個 "TABLE"
- Debug.Print i, "e Is Nothing ->", E Is Nothing
- Loop Until Not E Is Nothing
- Debug.Print i, "e Is Nothing ->", E Is Nothing, "e.all.Length", E.all.Length
- Loop Until E.all.Length >= IIf(i = 0, 431, 150) '
- Stop '之後按下F5
-
- Application.VBE.Windows("即時運算").Visible = False
- Application.VBE.MainWindow.Visible = False
- .Document.body.innerHTML = E.outerHTML
- .ExecWB 17, 2 ' Select All
- .ExecWB 12, 2 ' Copy selection
- With ActiveSheet
- .Range("A" & IIf(i = 0, 1, 27)).Select
- .PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
- With .Range(IIf(i = 0, "D16:D17", "C27:C28")).Interior
- .ColorIndex = 35
- .Pattern = xlSolid
- End With
- End With
- .Quit '關閉網頁
- End With
- Next
- End Sub
複製代碼 |
|