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 "~"
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
I realize that if the website changes the code is no good... is there a way
around that?
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
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.
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...