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

VBA-Excel: Login To Already Opened GMAIL In An Internet Explorer (IE)

To Login To Already Opened GMAIL In An Inter­net Explorer (IE) using Microsoft Excel,

Steps:

  • Cre­ate the object of Shell Application
  • Get all the win­dows using shellobject.Windows
  • Nav­i­gate all the windows
  • check if win­dow is Inter­net Explorer
  • if win­dow is IE then check if it is Gmail browser and store the object
  • Get the Page object of Gmail window.
  • 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 Shell Application

Set objShell = CreateObject(“Shell.Application”)

Get all the win­dows using shellobject.Windows

Set objAll­Win­dows = objShell.Windows

Nav­i­gate all the windows

For Each ow In objAllWindows

check if win­dow is Inter­net Explorer

If (InStr(1, ow, “Inter­net Explorer”, vbTextCom­pare)) Then

if win­dow is IE then check if it is Gmail browser and store the object

If (InStr(1, ow.locationURL, “mail.google.com”, vbTextCom­pare)) Then

Set objG­MAIL = ow

End If

Get the Page object of Gmail window.

Set obj­Page = objGMAIL.Document

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:

Sub login()

    Set objShell = CreateObject("Shell.Application")
    Set objAllWindows = objShell.Windows
    
    For Each ow In objAllWindows
        'MsgBox ow
        If (InStr(1, ow, "Internet Explorer", vbTextCompare)) Then
            'MsgBox ow.Hwnd & "  " & ow & "   " & ow.locationURL
            If (InStr(1, ow.locationURL, "mail.google.com", vbTextCompare)) Then
                Set objGMAIL = ow
            End If
        End If
    Next
    
    If objGMAIL Is Nothing Then
    Else
        Set objPage = objGMAIL.Document
        Set NameEditB = objPage.getElementByID("Email")
        NameEditB.Value = "xxxxx"
        Set PWDEditB = objPage.getElementByID("Passwd")
        PWDEditB.Value = "yyyyyy"
        Set SignIn = objPage.getElementByID("signIn")
        'SignIn.Click    Uncomment it when you put valid gmail credentails
    End If

End Sub

Login Gmail

Login Gmail

 

You may also like...

Leave a Reply

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

%d bloggers like this: