ありがとうございます!
試行錯誤したらできました!!
Private Declare PtrSafe Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long
Declare Function FindWindow Lib "User32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Const WM_COMMAND As Long = &H111&
Sub ie_CommandStateChange()
Dim hwnd As Long
Dim ie As InternetExplorer
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
お礼
ありがとうございます! 試行錯誤したらできました!! Private Declare PtrSafe Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long Declare Function FindWindow Lib "User32.dll" Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Const WM_COMMAND As Long = &H111& Sub ie_CommandStateChange() Dim hwnd As Long Dim ie As InternetExplorer 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
補足
早速の回答ありがとうございます! ie.Navigato2~を止まる前と、 後にそれぞれ入れてみました。 どっちもエラーは出ませんでしたが ダイアログボックスは消えませんでした。 恐らく止まってしまうところの後に入れて、そこで止まらなければ動くんじゃないかと思われます…。 なぜダイアログボックスが出ると処理が止まってしまうのでしょうか。