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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
The web site uses frames, a web page level 'above' the HTML you posted and wasn't obvious until you gave me the URL in the PM. Therefore you need to access the frame document from the frameset document on the Find Products by Keyword page by replacing:
Code:
Set ieDoc = .Document
with:
Code:
Set ieDoc = .Document.frames("main").Document
Here's the complete code with the URL kept private.
Code:
Sub LoginToEsales()
    Dim SearchString As String
    Dim ieApp As InternetExplorer
    Dim ieDoc As Object
    Dim ieTable As Object
    Set ieApp = New InternetExplorer
    
    With ieApp
        .Visible = True
        .Navigate "*** PRIVATE URL ***"
        While .Busy Or .ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
        Set ieDoc = .Document
    End With
    
    With ieDoc.loginform
        .operinit.Value = "gmbg"
        .Password.Value = "gmbg"
        .submit
    End With
    
    With ieApp
        While .Busy Or .ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
    End With
    
    With ieDoc.choosecust
         .setcustno.Value = "240"
         .submit
     End With
     
    With ieApp
        While .Busy Or .ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
        Set ieDoc = .Document.frames("main").Document
    End With

    With ieDoc.forms("ByKeyword")
        .Item("keywords").Value = "xyz"
        .submit
    End With
    
    With ieApp
        While .Busy Or .ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
    End With

End Sub
Tip - Internet Explorer shows only the frame source HTML, so you need to use IE Developer Tools (press F12) or Firefox to see the crucial frameset and frame source HTML.
 
Upvote 0
John, This works great! The only problem now is that for some reason it doesn't search for "xyz". It enters the value but returns results as if the field was left blank. I'm sure this is a simple fix. I'll look into it. Thanks again for your help!
 
Upvote 0
Apparently I'm still stuck. Try changing "xyz" to switch and see if you get a list of switches. I can see the value being entered but the results are the same no matter what I input. I get the same thing if I leave it blank and click go
 
Upvote 0
Replace:
Code:
    With ieDoc.forms("ByKeyword")
        .Item("keywords").Value = "xyz"
        .submit
    End With
with:
Code:
    ieDoc.forms("ByKeyword").Item("keywords").Value = "switch"
    With ieDoc.getElementsByName("submit")(0)
        .Focus
        .Click
    End With
 
Upvote 0
Hello guys,,

i'm also trying to do a similar thing here.. open a webpage from excel and login to it using userid and password.

i've used the same used that john has mentioned (changed the URL)
Rich (BB code):
Sub LoginToEsales()
    Dim SearchString As String
    Dim ieApp As InternetExplorer
    Dim ieDoc As Object
    Dim ieTable As Object
    Set ieApp = New InternetExplorer
    
    With ieApp
        .Visible = True
        .navigate "https://domino.amer.csc.com/clu1/Fi...ss.nsf&DocID=DA86D24F81A23FAC8525774200212A2D"
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        Set ieDoc = .document
    End With
    
    With ieDoc.loginform
        .operinit.Value = "gmbg"
        .Password.Value = "gmbg"
        .submit
    End With
    
    With ieApp
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
    End With
    
    With ieDoc.choosecust
         .setcustno.Value = "240"
         .submit
     End With
     
    With ieApp
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        Set ieDoc = .document.frames("main").document
    End With
    With ieDoc.forms("ByKeyword")
        .Item("keywords").Value = "xyz"
        .submit
    End With
    
    With ieApp
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
    End With
End Sub


but i get stuck up at
Rich (BB code):
 While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend

i face 'Automation error' at this line..

do i have to point it to any specific reference modules ?

Can you please provide any inputs here ?
 
Upvote 0
John_w trying to send you a PM but your box is full. Looking for additional help. Would be willing to compensate you for your time via paypal
 
Upvote 0
This code references a specific site. The username, password, and custno, are specific to my organization. This could be the issue. The line of code you are referencing that is giving you the error simply waits to execute the next command until the page finishes loading. Try this:

Code:
Sub LoginToCSC()
    Dim SearchString As String
    Dim ieApp As InternetExplorer
    Dim ieDoc As Object
    Dim ieTable As Object
    Set ieApp = New InternetExplorer
    
    With ieApp
        .Visible = True
        .navigate "https://domino.amer.csc.com/clu1/Fin...25774200212A2D"
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend 
        Set ieDoc = .document
    End With
    
    With ieDoc.Login
        .USER.Value = "Input your USER name here"
        .PASSWORD.Value = "Input your password here"
        .submit
    End With
End Sub
 
Upvote 0
John_w trying to send you a PM but your box is full. Looking for additional help. Would be willing to compensate you for your time via paypal
 
Upvote 0

Forum statistics

Threads
1,215,477
Messages
6,125,031
Members
449,205
Latest member
Eggy66

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