Ujjwal Vaish
Ujjwal Vaish

Reputation: 375

Logging in a website via vba

I am trying to login to Facebook using code from my Excel as follows:

 Sub CallChrome()
    Set ie = CreateObject("InternetExplorer.application")
        ie.Visible = True
        ie.Navigate ("https://www.fb.com")
        Do
            If ie.ReadyState = 4 Then
                ie.Visible = False
                Exit Do
            Else
                DoEvents
            End If
        Loop
        ie.Document.Forms(0).all("Username").Value = "username"
        ie.Document.Forms(0).all("Password").Value = "password"
        ie.Document.Forms(0).submit

    End Sub

However, it shows an error "Object Required error 424" , on the ie.Document.Forms(0)...... Although the login page is being displayed, I am not able to pass my credentials.

Upvotes: 0

Views: 1823

Answers (1)

Ujjwal Vaish
Ujjwal Vaish

Reputation: 375

This worked. I replaced this:

    ie.Document.Forms(0).all("Username").Value = "username"
    ie.Document.Forms(0).all("Password").Value = "password"

with this:

    ie.Document.all.Item("email").Value = "username"
    ie.Document.all.Item("pass").Value = "password"

Upvotes: 1

Related Questions