How to Log into Gmail Automatically

How to Log into Gmail Automatically with VBA. Google has changed its Gmail interface completely. Instead of opening gmail.com, we go directly to the login page of the URL.
Watch the video:

Watch the video on YouTube.

Here’s the complete VBA code to log into your Gmail account automatically:

Sub Login_Gmail()

‘Set a reference (Visual Basic Editor) > Tools > References) to the following libraries:
‘ a) Microsoft Internet Controls
‘ b) Microsoft HTML Object Library

Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim HTMLElement As MSHTML.IHTMLElement

With IE
.Visible = True
.Silent = True ‘avoid any pop-up
.navigate “https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin”
Do While .Busy Or .readyState <> READYSTATE_COMPLETE
DoEvents
Loop
End With

Call myTimer

Set HTMLDoc = IE.document

HTMLDoc.all.identifier.Value = “takyardinesh@gmail.com”
HTMLDoc.all.identifierNext.Click

With IE
Do While .Busy Or .readyState <> READYSTATE_COMPLETE
DoEvents
Loop
End With

Call myTimer

For Each HTMLElement In HTMLDoc.getElementsByName(“password”)
If HTMLElement.getAttribute(“type”) = “password” Then
‘enter the password for your account
HTMLElement.Value = “enteryourpassword”
Exit For
End If
Next HTMLElement

HTMLDoc.all.passwordNext.Click

Set IE = Nothing
Set HTMLDoc = Nothing
Set HTMLElement = Nothing

End Sub

Private Sub myTimer()

Dim timerStart As Single

Const pauseTIME As Integer = 5 ‘seconds

timerStart = Timer
Do Until Timer – timerStart > pauseTIME
DoEvents
Loop

End Sub

Further Reading:

How to automate login to Gmail

Published by

Dinesh Kumar Takyar

Welcome to exceltrainingvideos.com! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: http://youtube.com/familycomputerclub For a structured Excel VBA training course online you can visit: https://www.youtube.com/excelvbaonline

One thought on “How to Log into Gmail Automatically”

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.