Excel VBA to open Gmail

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

daniels012

Thread Starter
Joined
Feb 13, 2007
Messages
417
What code can I write to just open gmail?
I have a button now with VBA that saves the file as a pdf. I would like to add code to the button that would open gmail for me.

Any ideas?
Michael
 

OBP

Joined
Mar 8, 2005
Messages
19,896
Michael, have you looked on the gmail website help on VBA code.
I have the code for using gmail with Access, but not Excel.
 

OBP

Joined
Mar 8, 2005
Messages
19,896
On Error GoTo Err_Command19_Click
Dim attach As String
attach = "C:\Access\A-JCF-JCMRE.jpg"
Set cdomsg = CreateObject("CDO.message")
Set iConf = CreateObject("CDO.Configuration")

With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/con...tion/sendusing") = 2 'NTLM method
.Item("http://schemas.microsoft.com/cdo/con...ion/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/con...smptserverport") = 587
.Item("http://schemas.microsoft.com/cdo/con...tpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/con...ion/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/con...nectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/con...n/sendusername") = "Email goes here"
.Item("http://schemas.microsoft.com/cdo/con...n/sendpassword") = "password here"
.Update
End With
' build email parts

With cdomsg
Set .Configuration = iConf

.To = "Email goes here"
.BCC = "Email goes here"
.From = "Email goes here"
.Subject = "the email subject"
.Addattachment attach
.TextBody = "read attachment"
.Send
End With
Set cdomsg = Nothing
Exit_Command19_Click:
Exit Sub

Err_Command19_Click:
MsgBox Err.Description
Resume Exit_Command19_Click
 

Keebellah

Hans
Trusted Advisor
Joined
Mar 27, 2008
Messages
6,643
You will have to add two references in the VBA project

Microsoft Internet Controls
Microsoft HTML Object Library

Afetr I added these two references the compilation no longer thew an error, the code it'sself I haven't tested (yet)
 

Keebellah

Hans
Trusted Advisor
Joined
Mar 27, 2008
Messages
6,643
And yes, it opened Gmail, my account was lgged in so no password asked but the code is correct
 
Joined
Sep 4, 2003
Messages
4,916
The question has pretty much been answered but I thought I would just add that the control names used in the macro code can be obtained by viewing the webpage source code. I've been using a similar macro for years with no issues.

Rollin
 
Joined
Jul 25, 2004
Messages
5,458
OBP's method doesn't use IE, thus no browser overhead. It uses CDO to send via Gmail. I'd recommend using that.
 

daniels012

Thread Starter
Joined
Feb 13, 2007
Messages
417
Thank You Zack!
I am going to go try this and this may be a dunb question but?
The .... in the middle do I need something here?
.Item("http://schemas.microsoft.com/cdo/con...ion/smtpserver") = "smtp.gmail.com"
Mciahel D
 

daniels012

Thread Starter
Joined
Feb 13, 2007
Messages
417
I get an error on this line:
Set cdomsg = CreateObject("CDO.message")
It says variable not defined!

Michael
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top