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

x
?
Solved

Auto fill web forms using VBA

Posted on 2007-10-08
4
Medium Priority
?
7,731 Views
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.
0
Comment
Question by:marshalldavis
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
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
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
 

Author Comment

by:marshalldavis
ID: 20056898
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
 

Author Comment

by:marshalldavis
ID: 20059442
Ended up using

ieApp.Document.Forms(0).submit

to submit the second page
0
 

Expert Comment

by:SanjayShah
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
0

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