Log In to an Internet Site

Ease of Use


Version tested with

2000, 2003 

Submitted by:



Successfully log in to an Internet site or receive a message that a user is already logged in. 


Valid reasons include customising your logins from an Excel dropdown list. Invalid reasons are that you hate typing or you want to guess someone's password. 


instructions for use


Option Explicit Sub IE_login() Dim ie As InternetExplorer Dim C Dim ULogin As Boolean, ieForm Dim MyPass As String, MyLogin As String redo: MyLogin = Application.InputBox("Please enter your VBAX login", "VBAX username", Default:="login", Type:=2) MyPass = Application.InputBox("Please enter your VBAX password", "VBAX Password", Default:="Password", Type:=2) If MyLogin = "" Or MyPass = "" Then GoTo redo Set ie = New InternetExplorer ie.Visible = True ie.Navigate "http://www.vbaexpress.com" 'Loop until ie page is fully loaded Do Until ie.ReadyState = READYSTATE_COMPLETE Loop 'Look for password Form by finding test "Password" For Each ieForm In ie.Document.forms If InStr(ieForm.innertext, "Password") <> 0 Then ULogin = True 'enter details ieForm(0).Value = MyLogin ieForm(2).Value = MyPass 'login ieForm.submit Exit For Else End If Next If ULogin = False Then MsgBox "User is aleady logged in" Set ie = Nothing End Sub Sub SetRefs() Dim ObRef On Error Resume Next ' Adds Internet Controls Ref ThisWorkbook.VBProject.References.AddFromGuid "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 1, 1 End Sub

How to use:

  1. Copy the code above.
  2. Open your workbook.
  3. Hit Alt+F11 to open the Visual Basic Editor (VBE).
  4. From the menu, choose Insert-Module.
  5. Paste the code into the code window at right.
  6. Close the VBE, and save the file if desired.

Test the code:

  1. Run the macro SetRefs by going to Tools-Macro-Macros and double-click SetRefs. This sets the references to the Internet Controls library
  2. Run the macro AutomateIE by going to Tools-Macro-Macros and double-click IE_login.

Sample File:

IEauto (KB16).zip 12.97KB 

Approved by mdmackillop

This entry has been viewed 625 times.

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