+ Reply to Thread
Results 1 to 3 of 3

Sending email using Gmail and attaching workbook.

  1. #1
    Forum Contributor
    Join Date
    11-14-2012
    Location
    Kentucky
    MS-Off Ver
    Office 16
    Posts
    112

    Sending email using Gmail and attaching workbook.

    Hi all,

    This is my first post and I am having a bit of trouble. I am trying to send the active workbook as an attachment when a particular macro is executed. I am currently working with this macro and I can receive the email but not the attachment. I have tried adding many variants of .AddAttachment commands and i always get an error message. I hope one of your expertise can help me with my problem. Thanks for helping!

    Sub CDO_Mail_Small_Text_2()
    Dim iMsg As Object
    Dim iConf As Object
    Dim strbody As String
    Dim Flds As Variant

    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

    iConf.Load -1 ' CDO Source Defaults
    Set Flds = iConf.Fields
    With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "*****@gmail.com"
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "*****"
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
    .Update
    End With

    strbody = "Hi there" & vbNewLine & vbNewLine & _
    "This is line 1" & vbNewLine & _
    "This is line 2" & vbNewLine & _
    "This is line 3" & vbNewLine & _
    "This is line 4"



    With iMsg
    Set .Configuration = iConf
    .To = "*******@gmail.com"
    .CC = ""
    .BCC = ""
    ' Note: The reply address is not working if you use this Gmail example
    ' It will use your Gmail address automatic. But you can add this line
    ' to change the reply address .ReplyTo = "[email protected]"
    .From = """YourName"" <[email protected]>"
    .Subject = "Important message"
    .TextBody = strbody
    .Send
    End With

    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Sending email using Gmail and attaching workbook.

    You probably need to save a copy of the active workbook and attach that instead of the active workbook itself which is being accessed when the code is running. Try including this snippet in the With iMsg section:
    Please Login or Register  to view this content.
    If this doesn't work, please post the exact error message and say which line caused it, along with the entire code which produced it.
    Post responsibly. Search for excelforum.com

  3. #3
    Registered User
    Join Date
    09-12-2012
    Location
    chennai
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Sending email using Gmail and attaching workbook.

    Hi,

    please find attachement.

    Its have a simplest method to send emails with attachement.

    It may useful to you.


    Regards.

    Prasanna.E
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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