simulate pressing enter not working

G

geebee

hi,

i have the following. it basically puts the focus on the IE window. but im
trying to take it a step further by simulating hitting the ENTER key in the
IE window. i manually tested hitting ENTER in the IE window and it does what
i want but for some reason it does not work programmatically...

If lHwnd <> 0 Then
ShowWindow lHwnd, SW_SHOWNORMAL
Dim XT As Long
XT = BringWindowToTop(lHwnd) 'brings the IE window to top
Windows.Application.SendKeys "{ENTER}"
SendKeys "{ENTER}"

thanks in advance,
geebee
 
G

Gary Brown

GeeBee,
You've inadvertently posted to the Excel forum. You might want to try
again in the IE forum. Sorry we can't help.
Sincerely,
Gary Brown
 
P

Peter T

Gary, possibly as the OP has posted here if he is using Excel VBA

GeeBee, I expect there's a way to automate IE and its document and "submit"
without resorting to
SendKeys. It would though mean knowing a little more about the html document
and iexplore's methods (which I don't).

In the meantime you might check your IE window really is the active window
with the GetActiveWindow API. Failing that try the other two API's show
below (careful with line wrapping)

Public Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow"
() As Long
Public Declare Function SetForegroundWindow Lib "user32" Alias
"SetForegroundWindow" (ByVal hwnd As Long) As Long
Public Declare Function SetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd
As Long) As Long

None of these API's of course would ensue your particular button is in
focus, unless it is by default.

Regards,
Peter T
Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top