Connect Google Mail Account

     

     

    Download the Workbook

    Sub LoginToGoogleMail()

    'Define the GMail Worksheet
    Dim GSH As Worksheet
    Set GSH = ThisWorkbook.Sheets("GMail Login")

    'Declare a Variable for GMailID
    Dim GMail As String
    GMail = GSH.Range("C3").Value

    'Declare a Variable for Password
    Dim PWD As String
    PWD = GSH.Range("C4").Value

    'Define Internet Explorer
    Dim ie As InternetExplorer
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.navigate "https://accounts.google.com"
    Application.Wait Now + TimeSerial(0, 0, 3)

    'Convert the web page into HTML format
    Dim FirstPage As New HTMLDocument
    Set FirstPage = ie.document

    'Loop through all the elements and place googleMail ID
    For ElementNumber = 0 To FirstPage.all.Length - 1
    If FirstPage.all.Item(ElementNumber).innerText = GMail Then
    FirstPage.all.Item(ElementNumber).Click
    Application.Wait Now + TimeSerial(0, 0, 3)
    MailIDIdentified = "Yes"
    Exit For
    End If
    Next

    'After entering the Mail ID click on Next Button
    If MailIDIdentified <> "Yes" Then
    FirstPage.getElementById("identifierId").Value = GMail
    FirstPage.getElementById("identifierNext").Click
    Application.Wait Now + TimeSerial(0, 0, 3)
    End If

    'Convert the redirected web page into HTML format, enter the password
    Dim PwdPage As HTMLDocument
    Set PwdPage = ie.document
    For Each InputElement In PwdPage.getElementsByTagName("input")
    If InputElement.Name = "password" Then
    InputElement.Value = PWD
    Exit For
    End If
    Next

    'Click on Next Button
    PwdPage.getElementById("passwordNext").Click
    Application.Wait Now + TimeSerial(0, 0, 3)

    'Open Inbox of GoogleMail
    ie.navigate "https://mail.google.com/mail/u/0/#inbox"
    Application.Wait Now + TimeSerial(0, 0, 3)

    End Sub