最近接觸VBA
到了這個版才知道原來VB系列快走入歷史了.....
真是哀傷
我想問一下
我從YT上看到教學https://www.youtube.com/watch?v=dShR33CdlY8
他連到IE的方法是
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLButtons As MSHTML.IHTMLElementCollection
Dim HTMLButton As MSHTML.IHTMLElement
IE.Visible = True
IE.navigate "wiseowl.co.uk"
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
然後我又從另一人的網頁上
https://www.automateexcel.com/vba/automate-internet-explorer-ie-using/
看到另一種開IE的方法
'This will load a webpage in IE
Dim i As Long
Dim URL As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
URL = "https://www.automateexcel.com/excel/"
IE.Navigate URL
Application.StatusBar = URL & " is loading. Please wait..."
Do While IE.ReadyState = 4: DoEvents: Loop 'Do While
Do Until IE.ReadyState = 4: DoEvents: Loop 'Do Until
Application.StatusBar = URL & " Loaded"
我想問一下,這兩種方法會有什麼差別嗎
然後我也覺得有一點很奇怪
在等候IE載入時的程式碼
第1則是寫
Do While IE.ReadyState <> READYSTATE_COMPLETE
第2則卻是
Do While IE.ReadyState = 4
但是在VBA裡瀏覽物件的功能中查詢
READYSTATE_COMPLETE = 4
那上面2則的程式碼寫不就矛盾了嗎?
還是我誤會了什麼