【VBA】インプットボックスの操作(InternetExplorer)
インプットボックス
最近、40歳になったjimです。どうも✋
今回は『インプットボックスの操作』について記事を書いていきます。
本当は、【VBA】Webのテーブルデータ取得(InternetExplorer)でも書いたように、IEの操作を自動化したくないのですが。。。
しないといけないこともあって。。。
おそらく次の派遣先でも自動化するだろうし。。。
ってことで・・・
↓これがインプットボックス
↓HTMLだと
![]()
ちなみに・・・
↓テキストボックス
↓HTML
![]()
どっちの操作も一緒っす。
コードを書き散らす
わかりやすいように今回もIDを振ってあるので、インプットボックスをIDで指定してやります。
idが無い場合は、前回のtdように『何個目のinput』みたいな指定をしないと駄目っすね。
IEの操作は面倒。。。
はい、下に取得と入力について書いてあります。
参照設定してないと動かないので注意。
Option Explicit
Sub inputbox()
Const gakeUrl = "https://bw-rocket.com/2021/09/03/post-2780/"
Dim objIe As InternetExplorer
If GetWindow(objIe) = False Then
Set objIe = CreateObject("InternetExplorer.Application")
objIe.Visible = True
objIe.navigate gakeUrl
Call WaitLoad(objIe)
End If
'取得
Debug.Print objIe.document.getElementById("gakeid").Value
Debug.Print objIe.document.getElementsByName("gakename")(0).Value
'入力(前)
objIe.document.getElementById("gakeid").Value = "天才" & objIe.document.getElementById("gakeid").Value
'入力(後)
objIe.document.getElementById("gakeid").Value = objIe.document.getElementById("gakeid").Value & "天才"
'入力(上書き)
objIe.document.getElementById("gakeid").Value = "天才"
End Sub
Private Sub WaitLoad(ByVal objIe As InternetExplorer)
Do While objIe.Busy = True Or objIe.readyState <> 4
DoEvents
Loop
End Sub
Function GetWindow(ByRef objIe As InternetExplorer)
Const gakeTitle = "【VBA】テキストボックスの操作(InternetExplorer) | 崖っぷち派遣社員の日常"
Dim shellObject As Object
Dim windowObject As Object
Set shellObject = CreateObject("Shell.Application")
For Each windowObject In shellObject.Windows
If windowObject = "Internet Explorer" Then
If windowObject.document.Title = gakeTitle Then
Set objIe = windowObject
GetWindow = True
Exit For
End If
End If
Next
End Function
そゆ感じ。ではまた✋




ディスカッション
コメント一覧
まだ、コメントがありません