LoginSignup
6
10

More than 5 years have passed since last update.

VBA による IE の操作自動化

Posted at

ライブラリ参照設定

ツール > 参照設定 > Microsoft Internet Controls > OK
ツール > 参照設定 > Microsoft HTML Object Library > OK

IE オブジェクトの取得

Dim objIE As InternetExplorer
Set objIE = CreateObject("InternetExplorer.Application")

指定した Web ページを開く

objIE.Visible = True
objIE.Navigate 開きたいページの URL

Web ページ読込み完了まで待機する

Do While objIE.Busy Or objIE.ReadyState < READYSTATE_COMPLETE
   DoEvents
Loop

DOM の取得

Dim objDocument as HTMLDocument
set objDocument = objIE.Document
objDocument.getElementsByTagName(タグ名)(インデックス).innerText

起動中の IE ウィンドウを判別する

Dim objShell as Object, objWindow As Object
Set objShell = CreateObject("Shell.Application")

For Each objWindow In objShell.Windows
   If TypeName(objWindow.document) = "HTMLDocument" Then
      Set objIE = objWindow
      Exit For
   End if
Next
6
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
10