Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 536
  • Last Modified:

Navigating Browser using Excel VBA 1.

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
canesbr
Asked:
canesbr
  • 5
  • 4
  • 2
  • +1
2 Solutions
 
aikimarkCommented:
"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
 
canesbrAuthor Commented:
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
 
aikimarkCommented:
Change the IE variable definition
Dim IE As Object

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
canesbrAuthor Commented:
Did that. Still get error.
Regards
Brian
0
 
aikimarkCommented:
what error?
0
 
canesbrAuthor Commented:
Error 438 "Object doesn't support this property or method"
GetElementByID
Regards
Brian
0
 
aikimarkCommented:
What do these two statements do?
Doodly IE
Muddly IE

Open in new window

0
 
Glenn RayExcel VBA DeveloperCommented:
^Isn't it obvious? :-P
0
 
canesbrAuthor Commented:
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
 
Robert SchuttSoftware EngineerCommented:
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
 
canesbrAuthor Commented:
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
 
Robert SchuttSoftware EngineerCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now