Solved

Navigating Browser using Excel VBA 1.

Posted on 2014-11-02
12
299 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Photo Albums in PowerPoint Photo Albums are a very useful tool in PowerPoint and allow you quickly add a large number of images. The images can be formatted in a variety of ways so that you are able to create a professional looking presentation v…
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now