Help With VBA Code To Navigate Internet Explorer

hzrvkt

New Member
Joined
Jul 10, 2004
Messages
33
Let me start by saying that my programming skills are novice at best. However, I am attempting to write a sub routine to login to a website and enter data from a spreadsheet into a search field on the site. Logging in requires navigation through a series of three pages. I have successfully navigated through the first two. The problem is that on the third page when I attempt to reference an IE form called ByKeywords I get a "Run Time Error - 438 Object doesn't support this property or method". I've been stuck on this for a couple days and have searched every forum I could find.

Sub LoginToEsales()
Dim ieApp As InternetExplorer
Dim ieDoc As Object
Dim ieTable As Object
Set ieApp = New InternetExplorer
ieApp.Visible = True
ieApp.Navigate "My Website (unable to post link due to privacy concerns)"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
Set ieDoc = ieApp.Document
With ieDoc.loginform
.operinit.Value = "gmbg"
.passWord.Value = "gmbg"
.submit
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
With ieDoc.choosecust
.setcustno.Value = "240"
.submit
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
With ieDoc.ByKeywords 'This is where I get the Runtime Error - 438
.keywords.Value = "gmbg"
'.submit
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
UserForm1.Hide
End Sub



Here is the html code for the page I am trying to access:

<TABLE>
<TBODY>
<TR>
<TD>
<TABLE class=maintab border=0 cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD class=tabtitle>Find Products by Keyword </TD>
<TR class=wfill>
<TD colSpan=2 align=center>
<TABLE>
<TBODY>
<TR>
<TD align=center>
<DIV class=screenmsg>Note: Single department order entry!!!<BR>User can enter items to be charged to one department at a time. </DIV></TD></TR></TBODY></TABLE></TD>
<TD class=border><IMG src="/WI_web/Images/border.gif" width=2 height=1></TD></TR><!-- TB x155 removed the escape from the onSubmit -->
<FORM onsubmit="this.key.value = this.keywords.value; return true" method=get name=ByKeyword action=inquire-prod.r><INPUT name=sessid value=0x05988b17 type=hidden> <INPUT name=method value=keyword type=hidden> <INPUT name=file value=ICSP type=hidden> <INPUT name=searchby value=keyword type=hidden> <INPUT name=forward value=yes type=hidden> <INPUT name=lastrowid type=hidden> <INPUT name=key type=hidden>
<TR class=wfill>
<TD vAlign=top>
<TABLE class=1subtab border=0 cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD class=label>Keywords: </TD>
<TD class=field><INPUT onfocus='SelectText(this, "Enter any keywords (Optional)")' name=keywords maxLength=60 size=30> </TD></TR>
<TR>
<TD class=label>Warehouse: </TD>
<TD class=field><SELECT onfocus='Help("Select warehouse or use default")' name=whse> <OPTION selected value=BGCS>GM Bowling Green - HSS(BGCS)<OPTION value=2038>POU 1(2038)<OPTION value=2039>POU 2(2039)<OPTION value=2040>POU 4(2040)<OPTION value=2041>POU 6(2041)<OPTION value=2042>POU 7(2042)<OPTION value=2043>POU 8(2043)<OPTION value=2044>POU 9(2044)<OPTION value=2045>POU 10(2045)<OPTION value=2046>POU 11(2046)<OPTION value=2047>POU 12(2047)<OPTION value=2048>POU 13(2048)<OPTION value=2049>POU 15(2049)<OPTION value=2050>POU 16(2050)<OPTION value=2051>POU 17(2051)<OPTION value=2052>POU 19(2052)<OPTION value=2053>POU 20(2053)<OPTION value=2054>POU 22(2054)<OPTION value=2055>POU 23(2055)<OPTION value=2076>POU 24(2076)<OPTION value=2083>POU 25(2083)<OPTION value=2084>POU 26(2084)<OPTION value=2085>POU 27(2085)<OPTION value=3000>COVERS PRIME-1 2 CART(3000)<OPTION value=3001>PRIME-1 2 CART(3001)<OPTION value=3002>COVERS 1STCOLOR-1 2 CART(3002)<OPTION value=3003>1STCOLOR-1 2 CART(3003)<OPTION value=3004>COVERS 3RDCOLOR-1 2 CART(3004)<OPTION value=3005>3RDCOLOR-1 2 CART(3005)<OPTION value=3006>COVERS FASCIA-1 2 CART(3006)<OPTION value=3007>FASCIA-1 2 CART(3007)<OPTION value=3008>ROBOT ATTNDS-1 2 CART(3008)<OPTION value=3009>PAINT MIX-1 2 CART(3009)<OPTION value=BGWR>GMBG Warranty Repair Warehouse(BGWR)<OPTION value=BILL>HSS LLC(BILL)</OPTION></SELECT> </TD></TR></TBODY></TABLE></TD>
<TD vAlign=top>
<TABLE class=1subtab border=0 cellSpacing=0 cellPadding=2>
<TBODY>
<TR>
<TR class=colhead>
<TD class=headcell vAlign=middle colSpan=2 align=center><INPUT onfocus='Help("Click to search for products by keywords")' name=submit
<TR class=wfill>
<TD class=headcell colSpan=2 align=center><A href="get-cart-lines.r?sessid=0x05988b17&forward=yes&lastrowid="><IMG border=0 src="/WI_web/Images/cart.gif"></A><BR>
<TABLE>
<TBODY>
<TR>
<TD align=center>
<DIV class=screenmsg>Click cart button when finished entering products for a department. </DIV></TD></TR></TBODY></TABLE></TD>
<TR>
<TR>
></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><!-- Generated by Webspeed: Progress Communities: Clearspace: Progress Communities -->
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
This works for me. Try ieDoc.forms("ByKeyword") as shown.
Code:
Sub LoginToEsales()
    Dim ieApp As InternetExplorer
    Dim ieDoc As Object
    Set ieApp = New InternetExplorer
    ieApp.Visible = True
    ieApp.Navigate "C:\html.html"
    Do While ieApp.Busy: DoEvents: Loop
    Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Set ieDoc = ieApp.Document
    With ieDoc.ByKeyword
        .Keywords.Value = "gmbg"
    End With
    With ieDoc.forms("ByKeyword")
        .Keywords.Value = "abc"
    End With
End Sub
 
Upvote 0
John, thanks so much! I got past the line that was hanging me up. However, now the next line is hanging me up. I get a runtime 91 error on the line:

.keywords.value="abc"

It's as if VBA is treating keywords as something other than a ie object. I'm sure it is a simple syntax correction but I've exhausted my toolbox. Any thoughts?
 
Upvote 0
Try one of the four With clauses shown below. All four work for me.
Code:
Sub LoginToEsales()
    Dim ieApp As InternetExplorer
    Dim ieDoc As Object
    Set ieApp = New InternetExplorer
    ieApp.Visible = True
    ieApp.Navigate "C:\html.html"
    Do While ieApp.Busy: DoEvents: Loop
    Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Set ieDoc = ieApp.Document
    With ieDoc.ByKeyword
        .Keywords.Value = "gmbg"
    End With
    With ieDoc.forms("ByKeyword")
        .Keywords.Value = "abc"
    End With
    With ieDoc.forms("ByKeyword")
        .Item("keywords").Value = "xyz"
    End With
    With ieDoc.getElementsByName("keywords")(0)
        .Value = "qwerty"
    End With
End Sub
 
Upvote 0
Try .Focus on the element before setting its value, like this:
Code:
    With ieDoc.forms("ByKeyword")
        .Keywords.Focus = "abc"
        .Keywords.Value = "abc"
    End With
'Or
    With ieDoc.forms("ByKeyword")
        .Item("keywords").Focus
        .Item("keywords").Value = "xyz"
    End With
Try the other With statement clauses previously shown as well. If you still get an error, it might be because the element might not be ready to be referenced. To test this, set a breakpoint on the With statement, wait 2-3 seconds, then step to the .Value statement and see if it populates the input box.
 
Upvote 0
John, I still get the same runtime error. I tried sending you a message with the actual url I am working with but it seems your box is full.
 
Upvote 0

Forum statistics

Threads
1,223,714
Messages
6,174,052
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top