+ Reply to Thread
Results 1 to 9 of 9

Save & Send excel workbook in Gmail

Hybrid View

  1. #1
    Registered User
    Join Date
    02-10-2020
    Location
    USA
    MS-Off Ver
    2010
    Posts
    4

    Save & Send excel workbook in Gmail

    Hi there! I'm creating a shift log for our concierge to complete and I wanted to add a button in the sheet that they can click and it will save & send the workbook in an email through gmail. I have the email part working, but I can't figure out how to get it to attach the workbook. I had removed .attachements.add activeworkbook.fullname because the code didn't work at all with it in there.

    IMPORTANT: I'm an extreme noob to VBA and what I have so far is just from google searching. I appreciate any help anyone can offer!

    It wont let me post the code, it keeps saying "You are not allowed to post any kinds of links, images or videos until you post a few times."

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Save & Send excel workbook in Gmail

    Hello TCoffee2016,

    Welcome to the forum!

    What program are you using to send the email? My guess is Outlook.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    02-10-2020
    Location
    USA
    MS-Off Ver
    2010
    Posts
    4

    Re: Save & Send excel workbook in Gmail

    Quote Originally Posted by Leith Ross View Post
    Hello TCoffee2016,

    Welcome to the forum!

    What program are you using to send the email? My guess is Outlook.
    I'm using excel and trying to send the email through gmail.

  4. #4
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,620

    Re: Save & Send excel workbook in Gmail


  5. #5
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Save & Send excel workbook in Gmail

    but the question is is gmail
    • An account that is linked to an email client (outlook, thunderbird etc)
    • An account that you access by using an brower (edge, chrome firefox etc) and then compose the email from there?


    the first option is easy, the second much harder

  6. #6
    Registered User
    Join Date
    02-10-2020
    Location
    USA
    MS-Off Ver
    2010
    Posts
    4

    Re: Save & Send excel workbook in Gmail

    Quote Originally Posted by davsth View Post
    but the question is is gmail
    • An account that is linked to an email client (outlook, thunderbird etc)
    • An account that you access by using an brower (edge, chrome firefox etc) and then compose the email from there?


    the first option is easy, the second much harder
    The 2nd I can get it to send the email, its just getting it to save and attach the current workbook that's proving difficult.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Save & Send excel workbook in Gmail

    Hello TCoffee,

    I have an Invoice program I wrote to save the worksheet as PDF and then email it using my Gmail account. You will need to edit the code to change the User Name, Password, Email address or addresses, subject line, and the email body to match your own.

    This code will run correctly if you are signed into to your gmail account.

    Sub SendCDOEmail()
    
        Dim EmailAddr   As String
        Dim EmailBody   As String
        Dim FileName    As String
        Dim HTMLbody    As String
        Dim JobSite     As String
        Dim cdoMail     As Object
        Dim Password    As String
        Dim SendTo      As String
        Dim UserName    As String
        
     
            UserName = ""   ' // Your Gmail User Name
            Password = ""   ' // Your Gmail Password
            EmailAddr = ""  ' // Your Gmail email address
            
            SendTo = ""     ' // Email recipient
            Subject = ""    ' // The subject of your email
            
            FileName = ""   ' // Full path of the file to be attached
            
            JobSite = "<b>" & Replace(Range("C8"), "c/o", "") & "</b>"
            
            Set cdoMail = CreateObject("cdo.message")
            
            ' // Default email message.
            HTMLbody = "<!DOCTYPE html>"
            HTMLbody = HTMLbody & "<p>Dear " & Range("C7").Text & ",<br><br>"
            HTMLbody = HTMLbody & "Attached is the " & LCase(Range("E1").Text) & " for the job at " & JobSite & ". Please review the job for correctness. <br>"
            HTMLbody = HTMLbody & "If there any omissions or you want to make changes to this job, please either email me or contact David Rimer by phone.<br><br>"
            HTMLbody = HTMLbody & "Thank you for using Hummingbird Tree Service!<br><br>"
            HTMLbody = HTMLbody & "Sincerely,<br>"
            HTMLbody = HTMLbody & "Leith Ross</p>"
            HTMLbody = HTMLbody & "</body></html>"
                    
            With cdoMail.Configuration.Fields
                .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
                .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"   ' // smtp.mail.yahoo.com
                .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = UserName      ' // User Name
                .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Password ' // Password
                .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
                .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
                .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
                .Item("urn:schemas:httpmail:importance") = 1
                .Item("urn:schemas:httpmail:priority") = 1
                .Item("urn:schemas:mailheader:X-Priority") = 1
                .Update
            End With
    
            With cdoMail
                .From = EmailAddr
                .to = SendTo
                .Subject = Subject
                .HTMLbody = HTMLbody
                .TextBody = EmailBody
                .AddAttachment FileName
                .Send
            End With
    
    End Sub

  8. #8
    Registered User
    Join Date
    02-10-2020
    Location
    USA
    MS-Off Ver
    2010
    Posts
    4

    Re: Save & Send excel workbook in Gmail

    Quote Originally Posted by Leith Ross View Post
    Hello TCoffee,

    I have an Invoice program I wrote to save the worksheet as PDF and then email it using my Gmail account. You will need to edit the code to change the User Name, Password, Email address or addresses, subject line, and the email body to match your own.

    This code will run correctly if you are signed into to your gmail account.


    End Sub
    [/code]
    This was working great until I changed the body of the email text, now I'm getting an error saying:

    Rune-time error '-2147024864 (80070020)':

    The process cannot access the file because it is being used by another process.

    In the module it highlights the .addAttachement FileName

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Save & Send excel workbook in Gmail

    Hello TCoffee,

    My guess is the file that is opened by another process is the active workbook. You will need to save a copy of the active workbook and use the copy as your attachment.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Send excel file as attachment using gmail in macro?
    By fourmurphys in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-20-2019, 09:21 PM
  2. macro to send Email from Excel using gmail - error
    By hemantparmar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-20-2019, 10:20 AM
  3. Send Excel Workbook as PDF but not save
    By Dotreena in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-16-2018, 10:42 AM
  4. Send Workbook with Gmail not Outlook?
    By excelji in forum Excel General
    Replies: 1
    Last Post: 07-28-2014, 10:18 PM
  5. Send email through excel using gmail to multiple recipents
    By Neha3587 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-31-2014, 09:04 AM
  6. i want to send a active excel file as attachement by using gmail
    By kks279 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-17-2013, 01:44 PM
  7. Send Workbook as an Attachment Via Gmail - Code Review
    By psanghvi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-28-2012, 04:37 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1