Created
January 16, 2012 07:51
-
-
Save yu-tang/1619670 to your computer and use it in GitHub Desktop.
IEのロード待機サンプル(VBAのイベント駆動版)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' 要・Microsoft Internet Controls 参照設定 | |
Option Explicit | |
Private WithEvents ie As InternetExplorer | |
Private mDocumentComplete As Boolean | |
Private Sub Class_Initialize() | |
Set ie = New InternetExplorer | |
ie.Visible = True | |
Navigate "about:blank" | |
End Sub | |
Public Sub Navigate(ByRef URL As String) | |
mDocumentComplete = False | |
ie.Navigate2 URL | |
' 非同期で良いなら、以下でポーリングする必要はない。そのまま抜けて良し。 | |
Do | |
DoEvents | |
Loop Until mDocumentComplete | |
End Sub | |
Public Property Get IeObject() As InternetExplorer | |
Set IeObject = ie | |
End Property | |
Private Sub ie_DocumentComplete(ByVal pDisp As Object, URL As Variant) | |
mDocumentComplete = True | |
End Sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Sub TestIE_Automation() | |
Dim ie As CIE | |
Dim URL As Variant | |
Debug.Print "Start", Now | |
Set ie = New CIE | |
For Each URL In TargetURLs | |
ie.Navigate CStr(URL) | |
' 以下にやりたい処理を記述する。 | |
' ここではデモなので、単純に URL を出力。 | |
Debug.Print ie.IeObject.LocationURL | |
Next | |
Debug.Print "Exit", Now | |
End Sub | |
Private Function TargetURLs() As Variant() | |
TargetURLs = Array( _ | |
"http://www.example.com/1.html", _ | |
"http://www.example.com/2.html", _ | |
"http://www.example.com/3.html", _ | |
"http://www.example.com/4.html", _ | |
"http://www.example.com/5.html" _ | |
) | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment