Logging in a website via vba

2019-09-06 08:55发布

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.

1条回答
Luminary・发光体
2楼-- · 2019-09-06 09:31

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"
查看更多
登录 后发表回答