Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

VBA-Excel: Automate Internet Explorer (IE) using Microsoft Excel – Login into Gmail.

To Auto­mate the Inter­net Explorer (IE) using Microsoft Excel, say for exam­ple you want to login to your gmail account using Microsoft Excel. Please fol­low the steps men­tioned below

Steps:

  • Cre­ate the object of Inter­net Explorer
  • Make the Inter­net Explorer visible
  • Nav­i­gate to the “www.gmail.com”
  • Wait till the browser is busy and page is fully loaded
  • Get the doc­u­ment Object
  • Iden­tify the objects on the Page using “GetElementById”
  • Set the Authen­ti­ca­tion details in the Gmail login page
  • Iden­tify the Sign In But­ton using “GetEle­ment­ById” and Click on it


Cre­ate the object of Inter­net Explorer

Set objIEBrowser = CreateObject(“InternetExplorer.Application”)

Make the Inter­net Explorer visible

objIEBrowser.Vis­i­ble = True

Nav­i­gate to the www.gmail.com

        objIEBrowser.Navigate2 “www.gmail.com”

Wait till the browser is busy and page is fully loaded

Do While objIEBrowser.Busy

Loop

Do While objIEBrowser.ReadyState < 4

Loop

You can also call FnWait() for Explicit wait . Click Here

Get the doc­u­ment Object

Set obj­Page = objIEBrowser.Doc­u­ment

Iden­tify the objects on the Page using “GetElementById”

Set NameEd­itB = objPage.getElementByID(“Email”)

Set the Authen­ti­ca­tion details in the Gmail login page

NameEditB.Value = strUserName

Iden­tify the Sign In But­ton using “GetEle­ment­ById” and Click on it

Set SignIn = objPage.getElementByID(“signIn”)   

        SignIn.Click

 

Com­plete Code:

Function LoginGmail()

   Set objIEBrowser = CreateObject("InternetExplorer.Application")

   objIEBrowser.Visible = True

   objIEBrowser.Navigate2 "www.gmail.com"

   Call FnWaitForPageLoad(objIEBrowser)

     Set objPage = objIEBrowser.Document

   Call FnLogin(objPage, "[email protected]", "MyPassword")

   Call FnWaitForPageLoad

   Call FnWait(1)

End Function
Function FnLogin(objPage, strUserName, strPwd)

    Set NameEditB = objPage.getElementByID("Email")

  Set PWDEditB = objPage.getElementByID("Passwd")

  NameEditB.Value = strUserName

  PWDEditB.Value = strPwd

  Set SignIn = objPage.getElementByID("signIn")

 SignIn.Click

End Function
Function FnWait(intTime)

    newHour = Hour(Now())

    newMinute = Minute(Now())

    newSecond = Second(Now()) + intTime

    waitTime = TimeSerial(newHour, newMinute, newSecond)

    Application.Wait waitTime

End Function
Function FnWaitForPageLoad(objIEBrowser)

  Do While objIEBrowser.Busy

  Loop

  Do While objIEBrowser.ReadyState < 4

  Loop

End Function
Login Gmail using Excel

Login Gmail using Excel

 

 

You may also like...

2 Responses

  1. Orion says:

    Hi,
    How to send attached file (only sheet1) using vba excel with gmail, please..
    Thanks in advance

    • sumitjain says:

      Till now i have done send­ing mail using vba excel with microsoft out­look. Still work­ing with gmail. soon will post an arti­cle on that. If you want it with out­look i can pro­vide imme­di­ate help.

      Thanks
      Sumit

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: