Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sendkeys to a launched IE browser

108 views
Skip to first unread message

John

unread,
Sep 5, 2006, 12:09:02 PM9/5/06
to
Code is simple... and there is no error in code (that VBA discerns) but the
sendkeys commands do not move the cursor in the new IE window and doesn't
send the active cell value either. Any thoughts?

Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie

.Visible = True

.navigate "http://whatever.com"
.resizable = True
End With

'App.Activate "Microsoft Internet Explorer"
SendKeys "{TAB}"
SendKeys ActiveCell.Value
SendKeys "~"

Bill Pfister

unread,
Sep 5, 2006, 12:28:01 PM9/5/06
to
John, are you trying to fill in a form on a webpage or send a command to the
browser itself (such as "open page www.123.com)?

If you are trying to fill in a form on a page, my first guess is that you
aren't waiting long enough for the page to fully load. With the following
code I was able to browse to www.funny.com and enter "test" into the search
box. Sendkeys is very finicky and I would only use it as a last resort. If
the web page orientation (layout, tab-index, etc.) ever changes, your code
will break.

Regards,
Bill


Public Sub Test_IESendkeys()
Dim i As Long


Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")
With ie

.Visible = True

.navigate "http://www.funny.com"


.resizable = True
End With

Application.Wait (Now + TimeValue("0:00:10"))

'App.Activate "Microsoft Internet Explorer"
For i = 1 To 15
SendKeys "{TAB}"
Next i

SendKeys "test"
'SendKeys "~"
End Sub

John

unread,
Sep 5, 2006, 12:40:02 PM9/5/06
to
Thanks for the response Bill... it was a time thing... I am trying to launch
a new window and then dump a cell value into a search on a website. This
works by adding that wait command...

I realize that if the website changes the code is no good... is there a way
around that?

Randy Harmelink

unread,
Sep 5, 2006, 12:55:33 PM9/5/06
to
Rather than use SendKeys, you should be interacting with the web page
directly. For example, something like:

Set oIE = New InternetExplorer
oIE.Visible = True
oIE.Navigate Range("sURL")
Do: DoEvents: Loop Until oIE.ReadyState = READYSTATE_COMPLETE

Set oForm = oIE.Document.forms(0)
oForm("name1").Value = "Value1"
oForm("name2").Value = "Value2"
oForm("submitname").Click
Do: DoEvents: Loop While oIE.Busy
Do: DoEvents: Loop Until oIE.ReadyState = READYSTATE_COMPLETE

Set oForm = oIE.Document.forms(0)
oForm("cancelname").Click

Bill Pfister

unread,
Sep 5, 2006, 1:03:02 PM9/5/06
to
Firstly, let me disclaim my reference to www.funny.com. I have no
accociation with the site - it just happened to be the site that popped up
when I entered "whatever.com".

If the objects on the page are tagged, you can get a better "grip" when
you're trying to access them. You can find out by looking at the page source
and try to find a name property. In the "funny.com" site, you'll see that
the search field has a name: <input class="formItem" size="10" type=text
value="" name="0.7.31.1.3">. You can "tie" to this object with more
elaborate code. You will still be at the mercy of the site designers if they
change the control name, but it is considerably more reliable than using the
tab index.

I haven't written code tie directly to an object embedded in a webpage,
although I know sample code is out there.

NickHK

unread,
Sep 5, 2006, 10:39:36 PM9/5/06
to
John,
Depending on how this server handles the input, can you .Navigate2 the URL
that would exist after you have entered the criteria and clicked the button
?
e.g. This link takes you directly to Googles results page
http://www.google.co.uk/search?hl=en&q=Automation+IE+VB+-Net&btnG=Google+Search

You can build the required string with your ActiveCell.Value and go there
directly.

NickHK

"John" <Jo...@discussions.microsoft.com> wrote in message
news:1C8DBE8E-D795-4B53...@microsoft.com...

0 new messages