Discussion:
simulate hitting ENTER using VBA
(too old to reply)
geebee
2008-07-24 20:08:03 UTC
Permalink
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
rob^_^
2008-07-25 04:49:59 UTC
Permalink
Hi GeeBee,

Send Ctrl+D first to set the focus on the Address bar , before sending
{ENTER}

Regards.
Post by 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
Robert Aldwinckle
2008-07-25 17:30:12 UTC
Permalink
Post by 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.
What for?
Post by geebee
i manually tested hitting ENTER in the IE window and it does what
i want
As Rob indicated you need to consider keyboard focus.
*Where* was the keyboard focus before you hit Enter?
If it was on a link, e.g. if you tabbed to one you might
have to simulate that too.
Post by geebee
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}"
Oh. Well another thing that you might have to simulate is some _delay_
for the re-rendering to occur and the keyboard focus re-established
wherever it is to go. Otherwise what you are simulating with this code
is pressing Alt-Tab and then even before the window being switched to
is redrawn you would be hitting Enter. In that case your Enter might still
be eaten by the Taskbar.
Post by geebee
thanks in advance,
geebee
HTH

Robert Aldwinckle
---
rob^_^
2008-07-25 21:27:01 UTC
Permalink
Hi,

Also consider IE7 and 8 and Vista OS. You may find that your dreams will be
blown away by the security measures in these versions of IE.

Regards.
Post by 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
Loading...