Auto fill web forms using VBA

I need to be able to go to a website and have VBA automatically enter the Login, Password and client code (all of which I have) and move to the next page.

The following code  navigates there correctly but I have been unable to  fill in the fields either directly or with send keys.

    Set ieApp = CreateObject("InternetExplorer.Application")
   
    ieApp.Visible = True
    ieApp.Navigate "https://ecf.ganb.uscourts.gov/cgi-bin/show_case_doc?28,349918,,19383973,"

Any ideas would be greatly appreciated.
marshalldavisAsked:
Who is Participating?
 
justyndallmannCommented:
This may not be the best code, but it works for me.  

First set a reference to "Microsoft Internet Controls" (C:\WINDOWS\system32\shdocvw.dll).  But using CreateObject should do essentially the same thing.

The below code works with the page you provided.  You have to view the page source to get the names of the controls you want to fill.  

Dim ieApp As InternetExplorer
Dim iePage As HTMLDocument
Set ieApp = New InternetExplorer
ieApp.Visible = True
ieApp.Navigate "https://ecf.ganb.uscourts.gov/cgi-bin/show_case_doc?28,349918,,19383973,"
'wait for page to load
Do Until ieApp.ReadyState = READYSTATE_COMPLETE
Loop
Set iePage = ieApp.Document
iePage.Forms(0).Item("login").Value = "LOGIN"
iePage.Forms(0).Item("key").Value = "PASSWORD"
iePage.Forms(0).Item("clcode").Value = "CLIENT_CODE"
iePage.Forms(0).Item("button1").Click
0
 
marshalldavisAuthor Commented:
justyndallmann:

Your code works like a charm.  If I can push my luck on the second page (after the login) there is a single button to verify that you wish to enter the system.

The HTML for the page is:

<HTML><HEAD><link rel ="stylesheet" type="text/css" href="/styles/default.css">
<TITLE>TestSystemName</TITLE></HEAD><BODY BGCOLOR=F9F9F9 TEXT=000000 onLoad='SetFocus()'><SCRIPT LANGUAGE="JavaScript">
            var IsForm = false;
            var FirstField;
            function SetFocus() {
                  if(IsForm) {
                        if(FirstField) {
                              var ind = FirstField.indexOf('document.',0);
                              if(ind == 0)
                              {
                                    eval(FirstField);
                              }
                              else
                              {
                                    var Code = "document.forms[0]."+FirstField+".focus();";
                                    eval(Code);
                              }
                        } else {
                              var Cnt = 0;                        
                              while(document.forms[0].elements[Cnt] != null) {
                                    if(document.forms[0].elements[Cnt].type != "hidden") {
                                          document.forms[0].elements[Cnt].focus();
                                          break;
                                    }
                                    Cnt += 1;
                              }
                        }
                  }
                  return(true);
            }
            </SCRIPT>
<!-ShowPage(GENERICCDISPLAY)-> <P>To accept charges shown below, click on the 'View Document' button, otherwise click the 'Back' button on your browser.</P><FORM ENCTYPE='multipart/form-data' method=POST ACTION="/cgi-bin/show_case_doc?28,349918,,19383973,,1"><HR><CENTER><TABLE BORDER=1 BGCOLOR=white width="400"><TR><TH COLSPAN=4><FONT SIZE=+1 COLOR=DARKRED>Pacer Service Center </FONT></TH></TR><TR><TH COLSPAN=4><FONT COLOR=DARKBLUE>Transaction Receipt </FONT></TH></TR><TR></TR><TR></TR><TR><TD COLSPAN=4 ALIGN=CENTER><FONT SIZE=-1 COLOR=DARKBLUE>Thu Oct 11 09:47:32 EDT 2007</FONT></TD></TR><TR><TH ALIGN=LEFT><FONT SIZE=-1 COLOR=DARKBLUE> Pacer Login: </FONT></TH><TD ALIGN=LEFT><FONT SIZE=-1 COLOR=DARKBLUE> cw0133 </FONT></TH></TD><TH ALIGN=LEFT><FONT SIZE=-1 COLOR=DARKBLUE> Client Code: </FONT></TH><TD ALIGN=LEFT><FONT SIZE=-1 COLOR=DARKBLUE> system                           </FONT></TD></TR><TR><TH ALIGN=LEFT><FONT SIZE=-1 COLOR=DARKBLUE> Description: </FONT></TH><TD ALIGN=LEFT><FONT SIZE=-1 COLOR=DARKBLUE> Image28-0 </FONT></TD><TH ALIGN=LEFT><FONT SIZE=-1 COLOR=DARKBLUE> Case Number: </FONT></TH><TD ALIGN=LEFT><FONT SIZE=-1 COLOR=DARKBLUE> 05-71193-pwb </FONT></TD></TR><TR><TH ALIGN=LEFT><FONT SIZE=-1 COLOR=DARKBLUE> Billable Pages: </FONT></TH><TD ALIGN=LEFT><FONT SIZE=-1 COLOR=DARKBLUE> 2 </FONT></TD><TH ALIGN=LEFT><FONT SIZE=-1 COLOR=DARKBLUE> Cost: </FONT></TH><TD ALIGN=LEFT><FONT SIZE=-1 COLOR=DARKBLUE> 0.16 </FONT></TD></TR><TR></TR><TR></TR></TABLE></CENTER></HR><INPUT type=submit Value="View Document"></FORM>
</BODY></HTML>

Can I get the system to automatically click that button as well?
0
 
marshalldavisAuthor Commented:
Ended up using

ieApp.Document.Forms(0).submit

to submit the second page
0
 
SanjayShahCommented:
Is there any way to change list box containts & require event shold fire. Because in some web page it will display content of second list box only after fist list box value has selected and just passing value is not working.
E.g. After Selecting State in List Box of State the wab Page fill list of city in List Box of City and if we just change value of state using iePage.Forms(0).Item("State").Value = "STATENAME" then it is not filling city detail.
Is there any way to fire require event after filling details.

Sanjay Shah
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.