Public Declare Function FindWindowEx Lib "User32.dll" Alias "FindWindowExA" _
(ByVal hwndParent As Long, ByVal hwndChildAfter As Long, _
ByVal lpszClass As String, ByVal lpszWindow As String) As Long

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Option Explicit

Const WM_COMMAND As Long = &H111&

Sub IE画面上でのメッセージボックスを操作()

Dim hwnd As Long
Dim ie As Object
Dim a As Long, b As Long
Dim objtag As Object
Dim i As Long

Set ie = CreateObject("InternetExplorer.Application")

ie.Visible = True
ie.Navigate "http://kamicha1.web.fc2.com/Excel/Test20090726.html"

Do While ie.Busy Or ie.ReadyState < 4
DoEvents
Loop

Set objtag = ie.Document.getElementsByTagName("INPUT")
For i = 0 To objtag.Length - 1
If objtag(i).Value = "OK" Then

ie.Document.Script.setTimeout "javascript:document.getElementById('popOK').click()", 200

Sleep 1000

hwnd = FindWindow("#32770", "Web ページからのメッセージ")

If hwnd <> 0 Then

Debug.Print hwnd, ie.hwnd

PostMessage hwnd, WM_COMMAND, vbOK, 0

End If

Exit For

End If
Next i
End Sub

解説

下記のサイトを参考にしました。

https://teratail.com/questions/41585