Solved

Navigating Browser using Excel VBA 1.

Posted on 2014-11-02
12
407 Views
Last Modified: 2014-11-07
Excel 2007
Reference Microsoft Internet Controls
Trying to enter into a webpage a textbox
I get Error 438 "Object doesn't support this property or method"
in line  9  doc.GetElementByID("st").Value = "bose"
Please advise
Regards
Brian

Sub lime()
    Dim IE As SHDocVw.InternetExplorer
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate ("http://www.bestbuy.com")
    Doodly IE
    Muddly IE
    Set doc = IE.document
    doc.GetElementByID("st").Value = "bose"
    doc.GetElementByID("sb").Click
End Sub
Sub Doodly(IE)
    Do
        DoEvents
    Loop Until IE.readystate = 4
End Sub
Sub Muddly(IE)
    Do While IE.busy
        DoEvents
    Loop
End Sub

Open in new window

0
Comment
Question by:canesbr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 100 total points
ID: 40418992
"st" is the name attribute, not the id attribute.
<input type="text" value="" name="st" maxlength="90" placeholder="Search Best Buy" id="gh-search-input" />

Open in new window


Your locating by id statement should probably be:
doc.GetElementByID("gh-search-input").Value = "bose"

Open in new window

0
 

Author Comment

by:canesbr
ID: 40419449
Hi @aikimark
I still get the same Error 438
I notice that Document.getelementbyid does not resolve to Document.GetElementByID
So maybe something else is not set properly?
Regards
Brian
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40419510
Change the IE variable definition
Dim IE As Object

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:canesbr
ID: 40420345
Did that. Still get error.
Regards
Brian
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40420444
what error?
0
 

Author Comment

by:canesbr
ID: 40420516
Error 438 "Object doesn't support this property or method"
GetElementByID
Regards
Brian
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40420538
What do these two statements do?
Doodly IE
Muddly IE

Open in new window

0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40420759
^Isn't it obvious? :-P
0
 

Author Comment

by:canesbr
ID: 40420774
Posted in initial question.
They just are two different ways to wait for readiness
Sub Doodly(IE)
    Do
        DoEvents
    Loop Until IE.readystate = 4
End Sub
Sub Muddly(IE)
    Do While IE.busy
        DoEvents
    Loop
End Sub

Open in new window

Reminiscent of Kurt Vonnegut's
"We do doodly do what we must muddly must til we bust bodily bust"
Original:
We do, doodley do, doodley do, doodely do,
What we must, muddily must, muddily must, muddily must;
Muddily do, muddily do, muddily do, muddily do,
Until we bust, bodily bust, bodily bust, bodily bust.
Regardely Regards
Brian
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 400 total points
ID: 40427104
I'm not sure what your end goal is but apart from aikimark's adjustment for finding the input field, you need something similar for the button, for a bit of a quick and dirty solution try:
doc.GetElementsByTagName("button")(0).Click

Open in new window


To get IntelliSense on your doc variable you need to declare it:
Dim doc As HTMLDocument

Open in new window

For this to work, your VBA project needs to reference "Microsoft HTML Object Library".

I attached a workbook with the adjusted code.
tst.xlsm
0
 

Author Comment

by:canesbr
ID: 40427727
Hi Robert
I have references to "Microsoft HTML Object Library" and to "Microsoft Internet Controls"
I ran Sub lime in your attachment
I get runtime error 13 Type mismatch on statement "Set doc = IE.document"
<sigh>
Please advise
Regards
Brian
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 40427868
Ah yes I get the same error now, the first time I run it, because a language choice page is displayed. When I choose a language and check 'remember' then the second time it works so I guess we need to 'defeat' that page, can you confirm that works the same for you?
0

Featured Post

Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question