1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Excel VBA to open Gmail

Discussion in 'Business Applications' started by daniels012, Nov 2, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. daniels012

    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
     
  2. OBP

    OBP

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

    DoubleHelix Banned

    Joined:
    Dec 9, 2004
    Messages:
    24,388
  4. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    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
     
  5. Jimmy the Hand

    Jimmy the Hand

    Joined:
    Jul 28, 2006
    Messages:
    1,223
    Came across this one just today. A knowledge base item from VBAX:
    http://www.vbaexpress.com/kb/getarticle.php?kb_id=973
    Not sure if it works, as it's 2 years old code. Gmail's page might have changed since.
    Jimmy

    Update:
    It should work. The used control IDs on gmail login page are still the same.
     
  6. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,608
    First Name:
    Hans
    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)
     
  7. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,608
    First Name:
    Hans
    And yes, it opened Gmail, my account was lgged in so no password asked but the code is correct
     
  8. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    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
     
  9. Zack Barresse

    Zack Barresse

    Joined:
    Jul 25, 2004
    Messages:
    5,452
  10. daniels012

    daniels012 Thread Starter

    Joined:
    Feb 13, 2007
    Messages:
    417
    This is using IE
    What about opening Chrome?
     
  11. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,608
    First Name:
    Hans
  12. Zack Barresse

    Zack Barresse

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

    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?
    Mciahel D
     
  14. daniels012

    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
     
  15. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    See Keebellah's post at #6 about setting VBA References.
     
  16. Sponsor

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 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1025141

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice