LoginSignup
0
1

More than 5 years have passed since last update.

VBAで自動的にサイトの特定箇所に文字入力をする際の注意点

Posted at

一番初めに開いたサイトの次のページを表示し、そのページに自動で文字を入力させたい時の注意点を自分なりに発見したので記す。

プログラミングは細かく指示をしなくてはならない。
「どこに」「何を」「どのように」するのかを指示するのが重要である。

一番初めに開いたサイトの次のページに文字を入力させたい場合

例えば↓↓

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Zoom\ZoomFactor",100000,"REG_DWORD"

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True

objIE.Navigate "一番初めのURL"

Do Until objIE.Busy = False
    WScript.sleep(250)
Loop

objIE.Document.Forms(0).Item(2).value = "" ’ログインし次のページに遷移
objIE.Document.Forms(0).Item(3).value = ""
objIE.Document.Forms(0).Submit

Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.AppActivate "Explorer"

WScript.sleep(7000)

Dim strUrl
strUrl = "ログイン後のサイトのURL" ’ここでログイン後のURLを指定

objIE.navigate strUrl

WScript.sleep(7000)

Dim htmlDoc
Set htmlDoc = objIE.document

htmlDoc.getElementById("name").Value = "入力文字"

のように、場所を指定してあげることが重要。

Dim strUrl
strUrl = "ログイン後のサイトのURL" ’ここでログイン後のURLを指定

これが抜けてしまうと、一番最初のページで入力すると言うことになってしまうので
「オブジェクトがない」と言うエラーが起こる。

0
1
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
0
1