Multiple Apps

Start web page that requires password (Log onto gmail)

Ease of Use

Hard

Version tested with

2003 

Submitted by:

Oorang

Description:

This will show you how to take control of Internet Explorer, provide logon credentials, and sign into a website that requires a username and password. 

Discussion:

This code requires you to know the control names of the username and password fields, and the submit button. This information is available in the source code of the login page of any website, but you must find it. A good starting place is to look for the keyword "name". 

Code:

instructions for use

			

Public Sub LaunchGamil() Const strURL_c As String = "http://mail.google.com" Const strUsr_c As String = "1@2.3" Const strPwd_c As String = "foobarbaz" Dim objIE As SHDocVw.InternetExplorer Dim ieDoc As MSHTML.HTMLDocument Dim tbxPwdFld As MSHTML.HTMLInputElement Dim tbxUsrFld As MSHTML.HTMLInputElement Dim btnSubmit As MSHTML.HTMLInputElement On Error GoTo Err_Hnd 'Create Internet Explorer Object Set objIE = New SHDocVw.InternetExplorer 'Navigate the URL objIE.Navigate strURL_c 'Wait for page to load Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop 'Get document object Set ieDoc = objIE.Document 'Get username/password fields and submit button. Set tbxPwdFld = ieDoc.all.Item("Passwd") Set tbxUsrFld = ieDoc.all.Item("Email") Set btnSubmit = ieDoc.all.Item("signIn") 'Fill Fields tbxUsrFld.Value = strUsr_c tbxPwdFld.Value = strPwd_c 'Click submit btnSubmit.Click 'Wait for page to load Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop Err_Hnd: '(Fail gracefully) objIE.Visible = True End Sub

How to use:

  1. Press Alt-F11 to launch Visual Basic Editor.
  2. Insert a standard module.
  3. Paste code.
  4. From Tools menu click "Reference".
  5. Set a reference to Microsoft Internet Controls (shdocvw.dll).
  6. Set a reference to Microsoft HTML Object Library (mshtml.dll).
  7. Update the constant in the code to a valid username and password.
  8. From the debug menu click compile.
  9. Run.
 

Test the code:

  1. Update the constant in the code to a valid username and password.
  2. From the debug menu click compile.
  3. Run.
 

Sample File:

IE_Example.zip 13.3KB 

Approved by mdmackillop


This entry has been viewed 237 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express