Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trying to log into facebook using VBA

Tags:

excel

vba

I just started toying with VBA about a week ago. I can open IE and get to facebook. I can even enter my email in the right slot(because the cursor is already selected that spot). I cant seem to find a way to select the password field to enter my password. Let alone hit the log in button. Please help

here is my code so far

Sub facebookPost()

    Dim IE As Object

    Set IE = CreateObject("INTERNETEXPLORER.Application")
    IE.Navigate ("www.Facebook.com")
    IE.Visible = True

    Do While IE.Busy
      DoEvents
    Loop

    Application.Wait (Now + TimeValue("00:00:02"))

    IE.Document.all.Item("email").Value = "*******"
    IE.Document.all.Item("pass").Value = "********"
End Sub
like image 356
Timothy Hall Avatar asked Oct 26 '25 16:10

Timothy Hall


1 Answers

This is the source of the button

<label class="uiButton uiButtonConfirm" id="loginbutton" for="u_0_4"><input value="Log in" tabindex="4" id="u_0_4" type="submit"></label>

This works for me

IE.Document.all.Item("loginbutton").Click

So your code looks like this

Sub facebookPost()
    Dim IE As Object
    Dim sUser As String, sPass As String

    '~~> Change as Applicable
    sUser = "Blah Blah"
    sPass = "Blah Blah"

    Set IE = CreateObject("INTERNETEXPLORER.Application")

    IE.Navigate ("www.Facebook.com")
    IE.Visible = True

    Do While IE.Busy: DoEvents: Loop

    Application.Wait (Now + TimeValue("00:00:02"))

    IE.Document.all.Item("email").Value = sUser
    IE.Document.all.Item("pass").Value = sPass
    IE.Document.all.Item("loginbutton").Click
End Sub
like image 87
Siddharth Rout Avatar answered Oct 29 '25 17:10

Siddharth Rout