[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Auto fill web forms using VBA

Posted on 2007-10-08
Medium Priority
Last Modified: 2013-11-27
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.
Question by:marshalldavis
  • 2

Accepted Solution

justyndallmann earned 2000 total points
ID: 20050078
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
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"

Author Comment

ID: 20056898

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)
                                    var Code = "document.forms[0]."+FirstField+".focus();";
                        } else {
                              var Cnt = 0;                        
                              while(document.forms[0].elements[Cnt] != null) {
                                    if(document.forms[0].elements[Cnt].type != "hidden") {
                                    Cnt += 1;
<!-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>

Can I get the system to automatically click that button as well?

Author Comment

ID: 20059442
Ended up using


to submit the second page

Expert Comment

ID: 29663870
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

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

872 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