-
Oct 10th, 2018, 10:53 PM
#1
Thread Starter
New Member
BM_CLICK not working
I am opening a web page (HTML Document type) that also opens a pop up that has "OK" button. I have the code to click the "OK" button but it is not working. code does find popup window and "OK" Button
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal _
wParam As Long, lParam As Any) As Long
Private Const BM_CLICK As Long = &HF5&
Private 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
Sub EMS_P1()
'------P1--------
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Top = 0
objIE.Left = 0
objIE.Width = 800
objIE.Height = 600
objIE.AddressBar = 0
objIE.StatusBar = 0
objIE.Toolbar = 0
objIE.Visible = True 'We will see the window navigation
objIE.navigate ("http://claimportalch.prodlb.travp.net/claimportalcommon2/default.aspx")
'Do
'DoEvents
'Loop Until objIE.ReadyState = 4
Dim hwndParent As Long
hwndParent = FindWindow(vbNullString, "Message from webpage")
Debug.Print ("findwindow: " & hwndParent)
Dim hwndButton As Long
hwndButton = FindWindowEx(hwndParent, ByVal 0&, "Button", "OK")
Debug.Print ("OK: " & hwndButton)
hwndButton = PostMessage(hwndButton, BM_CLICK, 0, 0)
Debug.Print ("Clicked: " & hwndButton)
End sub
Pop up (doesn't look HTML) has title "Message from webpage". it has just one button name "OK". Can someone help with VBA code to either click it or press enter key so that pop disappears. I have used Send and postmessage functions but they are not able to click the "OK" button
Here is what I get when using PostMassage
findwindow: 3806110
OK: 2688002
Clicked: 1
-
Oct 11th, 2018, 03:19 PM
#2
Re: BM_CLICK not working
i tried to test, but the navigation failed
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 11th, 2018, 03:39 PM
#3
Re: BM_CLICK not working
Have you tried alternative messages? Sendmsg WM_LBUTTONDOWN then WM_LBUTTONUP
I've had similar situations where that has worked and other click messages didn't, and others where PostMessage didn't work but SendMessage did; I always use the latter with the WM_ messages above.
Last edited by fafalone; Oct 11th, 2018 at 03:43 PM.
-
Oct 11th, 2018, 03:55 PM
#4
Thread Starter
New Member
Re: BM_CLICK not working
This is secured page and unfortunately will not run for you
-
Oct 11th, 2018, 03:58 PM
#5
Thread Starter
New Member
Re: BM_CLICK not working
I will try ...how the code will look like ( I am new to this)
-
Oct 11th, 2018, 10:08 PM
#6
Re: BM_CLICK not working
Replace
hwndButton = PostMessage(hwndButton, BM_CLICK, 0, 0)
with
Call SendMessage(hwndButton, WM_LBUTTONDOWN, 0&, ByVal 0&)
Call SendMessage(hwndButton, WM_LBUTTONUP, 0&, ByVal 0&)
If no-go also try replacing the 'Call SendMessage' with 'Call PostMessage' (no other changes needed). Btw, neither of those returns an HWND, so never use hwndButton = with them.
If you need the declares:
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Last edited by fafalone; Oct 11th, 2018 at 10:29 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|