Tuesday, September 20, 2011

Log in to google or facebook account using excel





Login to Google Account using VBA


Have you ever thought of automating your login to google account or any other account using excel macros?
Hear is the simple macro to log in to google account.

Note: Change to your user name and password.
Code: For google account
****************************************************
Sub Login_google()
    
    Dim ie As Object
    
    Set ie = CreateObject("InternetExplorer.Application")
    
    ie.navigate "https://www.google.com/accounts/Login"
    
    ie.Visible = True
    
    Do While ie.Busy And Not ie.readyState = 4
        DoEvents
    Loop
    
    DoEvents
    
    ie.document.all.Item("Email").Value = "Rajendiran"
    ie.document.all.Item("passwd").Value = "******"
    ie.document.all.Item("signIn").Click
    
End Sub

****************************************************

 Code: For Facebook account

****************************************************
Sub Login_facebook()
    
    Dim ie As Object
    
    Set ie = CreateObject("InternetExplorer.Application")
    
    ie.navigate "http://www.facebook.com/login.php"
    
    ie.Visible = True
    
    Do While ie.Busy And Not ie.readyState = 4
        DoEvents
    Loop
    
    DoEvents
    
    ie.document.all.Item("email").Value = "rajendiran@mymail.com"
    ie.document.all.Item("pass").Value = "*******"
    ie.document.all.Item("login").Click
    
End Sub

****************************************************

5 comments:

  1. Great script! I tested on few mail sites an it works fine!
    But ... I don't like that I have to change those control names in the quotes: ie.document.all.Item("ControlName").Value
    Isn't there a way to get those names from a table/txtbox control on a form???
    I tried something like:
    Set CtrName = "ie.Document.all.Item(" & Chr(34) & Me.tag1 & Chr(34) & ")"
    CtrName.Value = Me.Username
    But it doesn't work...
    Any ideas?

    ReplyDelete
  2. Hi there. I tried this script but I am encountering an error.
    Error message: Run-time error 91: Object variable or With block variable not set
    Line affected: ie.document.all.Item("passwd").Value = "*********"
    I think the website can only fetch the provided email in the program and not the provided password. Can someone help me fix this? Thanks.

    ReplyDelete
    Replies
    1. Google login is actually very complex. Depending on if you've signed in before/you're currently signed in, there are like 5 different pages you could come upon when you initially navigate. I'm currently working on a script that handels every scenario. Email me if you're interested. Richter.Jonathan.R@gmail.com.

      Delete
  3. Replace "signIn" with "Next" in order to get it to login properly.

    ReplyDelete
  4. Also, add in "On Error Resume Next" to handle case when you are already logged in.

    ReplyDelete