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 Automate the Internet Explorer (IE) using Microsoft Excel, say for example you want to login to your gmail account using Microsoft Excel. Please follow the steps mentioned below

Steps:

  • Create the object of Internet Explorer
  • Make the Internet Explorer visible
  • Navigate to the “www.gmail.com”
  • Wait till the browser is busy and page is fully loaded
  • Get the document Object
  • Identify the objects on the Page using “GetElementById”
  • Set the Authentication details in the Gmail login page
  • Identify the Sign In Button using “GetElementById” and Click on it


Create the object of Internet Explorer

Set objIEBrowser = CreateObject(“InternetExplorer.Application”)

Make the Internet Explorer visible

objIEBrowser.Visible = True

Navigate 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 document Object

Set objPage = objIEBrowser.Document

Identify the objects on the Page using “GetElementById”

Set NameEditB = objPage.getElementByID(“Email”)

Set the Authentication details in the Gmail login page

NameEditB.Value = strUserName

Identify the Sign In Button using “GetElementById” and Click on it

Set SignIn = objPage.getElementByID(“signIn”)   

        SignIn.Click

 

Complete 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 sending mail using vba excel with microsoft outlook. Still working with gmail. soon will post an article on that. If you want it with outlook i can provide immediate help.

      Thanks
      Sumit

Leave a Reply

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

%d bloggers like this: