Solved

Navigating Browser using Excel VBA 1.

Posted on 2014-11-02
12
358 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
  • 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
Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

837 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