Hello Will,
Here is macro to log on to Gmail with Internet Explorer. You will need to set a reference to Microsoft Internet Controls in your VBA project for this to run. Place this macro in a Standard VBA module. Change the UserName, your email name, and password as well before running it.
'Author: Leith Ross
'Summary: Logs on to Gmail using Internat Explorer
'This code first requires setting a reference to Microsoft Internet Controls.
'In the Object Browser the properties, methods, and events appear under SHDocVw.
Sub LogOnToGmail()
Dim IEapp As Object
Dim Password As String
Dim UserName As String
Dim URL As String
URL = "https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%3Fnsr%3D1%26ui%3Dhtml%26zy%3Dl<mpl=default<mplcache=2&hl=en/"
UserName = "LeithRoss"
Password = "notmyrealpassword"
Set IEapp = New InternetExplorer
' Launch Internet Explorer and go to the site
With IEapp
.Visible = True
.Navigate URL
End With
' Wait until Internet Explore finishes loading
While IEapp.Busy
DoEvents
Wend
' Insert your email name
IEapp.Document.all("Email").Value = UserName
' Wait till the page is loaded
While IEapp.Busy
DoEvents
Wend
' Insert your password
IEapp.Document.all("passwd").Value = Password
' Wait till the page is loaded
While IEapp.Busy
DoEvents
Wend
' Clicks the Sign In button
IEapp.Document.all("signIn").Click
While IEapp.Busy
DoEvents 'wait until IE is done loading page.
Wend
End Sub
Setting the needed Reference
1) If you are in Excel, press ALT+F11 to activate the [b]VBE{/b]
2) Click on Tools
3) Click on References...
4) Scroll through the References list using the Down Arrow. The list is in alphabetical order.
5) Look for Microsoft Internet Controls
6) When you find it, press the Space Bar to select it.
7) Press Enter to exit.
8) Press CTRL+S to Save the reference in your project.
Sincerely,
Leith Ross
Bookmarks