How to Log into Gmail Automatically

How to Log into Gmail Automatically with VBA. Google has changed its Gmail interface completely. Instead of opening, 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 “”
Do While .Busy Or .readyState <> READYSTATE_COMPLETE
End With

Call myTimer

Set HTMLDoc = IE.document

HTMLDoc.all.identifier.Value = “”

With IE
Do While .Busy Or .readyState <> READYSTATE_COMPLETE
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


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

End Sub

Further Reading:

How to automate login to Gmail

Published by

Dinesh Kumar Takyar

Welcome to! 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: For a structured Excel VBA training course online you can visit:

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.