Excel VBA html login

Posted on 2009-12-29
Last Modified: 2012-05-08
I am trying to use the following to login to a website where in later code Il scan the html page for relavant tags so to grab the data on the page. However, I am unable to get to the login object to enter my username and password str. Any help is much appreciated.

Sub Website()

Dim ie As Object, iebody As String, strURL As String, strUsername As String, strPassword As String

Set ie = CreateObject("InternetExplorer.Application")

strURL = ""
strUsername = "?"
strPassword = "?"

ie.Navigate strURL
'Wait until page is loaded.
While ie.ReadyState < 3  ' READYSTATE_COMPLETE = 4
ie.Visible = True
ie.Document.All("Username:").Value = strUsername  ---> this is where I am running into an error.  The str text is not being filled onto the website.>
ie.Document.All("password").Value = strPassword
'Wait until page is loaded.
While ie.ReadyState < 3  ' READYSTATE_COMPLETE = 4

Application.Wait (Now + TimeValue("0:00:05"))

iebody = ie.Document.body.innerhtml

If InStr(iebody, "The information you entered is invalid.") <> 0 Then
    MsgBox "Login failed!", vbCritical + vbOKOnly
    MsgBox "Login successful!", vbInformation + vbOKOnly
End If

Set ie = Nothing

End Sub
Question by:lgenerator
    LVL 29

    Expert Comment

    The website looks like it should be:


    ie.Document.All("fcl_userid").Value = "userid"
    ie.Document.All("fcl_password").Value = "password"
    LVL 29

    Accepted Solution

    Your example seems to fail with the revisions but this should work for you.
    Option Explicit
    Public Sub Login(ByVal szUserName As String, ByVal szPassword As String)
      Dim IE As Object
      Set IE = CreateObject("InternetExplorer.Application")
      IE.Visible = True
      IE.Navigate ""
      ' Wait for the page to load.
      Do While IE.Busy Or IE.ReadyState <> 4
      IE.Document.getElementById("fcl_userid").Value = szUserName
      IE.Document.getElementById("fcl_password").Value = szPassword
      ' Destroy object.
      Set IE = Nothing
    End Sub

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Many companies are making the switch from Microsoft to Google Apps ( Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
    This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now