Log Into Gmail Account From Excel,

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Log Into Gmail Account From Excel,

Post by adam »

Hi anyone,

Following is the code which I'm trying to log into my gmail account from Microsoft excel. The code opens the page but does not sign me in. What am I doing wrong in here?

Code: Select all

Option Explicit

Sub IE_login()
    Dim ie As InternetExplorer
    Dim C
    Dim ULogin As Boolean, ieForm
    Dim MyPass As String, MyLogin As String

redo:
    MyLogin = Application.InputBox("Please enter your Gmail login", "Gmail username", Default:="login", Type:=2)
    MyPass = Application.InputBox("Please enter your Gmail password", "Gmail Password", Default:="Password", Type:=2)

    If MyLogin = "" Or MyPass = "" Then GoTo redo

    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "http://www.gmail.com"

    'Loop until ie page is fully loaded
    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop

    'Look for password Form by finding test "Password"
    For Each ieForm In ie.Document.forms
        If InStr(ieForm.innertext, "Password") <> 0 Then
            ULogin = True
            'enter details
            ieForm(0).Value = MyLogin
            ieForm(2).Value = MyPass
            'login
            ieForm.submit
            Exit For
        Else
        End If
    Next
    If ULogin = False Then MsgBox "User is aleady logged in"
    Set ie = Nothing
End Sub

Sub SetRefs()
    Dim ObRef
    On Error Resume Next
    ' Adds Internet Controls Ref
    ThisWorkbook.VBProject.References.AddFromGuid "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 1, 1
End Sub
Any help on this would be kindly appreciated.

Thanks in advance.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78484
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Log Into Gmail Account From Excel,

Post by HansV »

Why would you want to login to Gmail from Excel? Isn't it easier to login directly on the Gmail page?
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Log Into Gmail Account From Excel,

Post by adam »

Because my workbook is to be based on to log into gmail from excel.

Thanks in advance.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78484
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Log Into Gmail Account From Excel,

Post by HansV »

But you only need to login to Gmail once. After that, you'll remain logged in.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Log Into Gmail Account From Excel,

Post by adam »

Yeah true. But the intention is to force the use to use excel. Instead of opening a webpage from either desktop of from any other source. So that the users would be uploading data to be mailed from the excel application.

I hope I've made my question clear.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78484
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Log Into Gmail Account From Excel,

Post by HansV »

The Gmail login page that I use does not conform to the code that you posted, but I have no idea how the login page works, so I can't help you. Moreover, not everyone uses gmail.com. Many users in the UK, for example, have a gmail.co.uk e-mail address, so even a version that works for gmail.com would fail for those users. I'd instruct the users to log into Gmail before running the rest of your code.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Log Into Gmail Account From Excel,

Post by adam »

Thanks for the reply and the suggestion.
Best Regards,
Adam

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Log Into Gmail Account From Excel,

Post by adam »

Here is a http://vbaexpress.com/kb/getarticle.php?kb_id=973working example to access gmail from excel.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78484
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Log Into Gmail Account From Excel,

Post by HansV »

Good to see that you found the solution.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Log Into Gmail Account From Excel,

Post by adam »

Thanks. Usually I don't give on things that I try for :)
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78484
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Log Into Gmail Account From Excel,

Post by HansV »

I have moved this thread to the VBA forum because it is not specific to Excel.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Log Into Gmail Account From Excel,

Post by adam »

Nevermind.
Best Regards,
Adam