+ Reply to Thread
Results 1 to 6 of 6

Creating email from excel list with attachment

Hybrid View

  1. #1
    Registered User
    Join Date
    01-11-2010
    Location
    Brandon, FL
    MS-Off Ver
    Excel 2007
    Posts
    3

    Creating email from excel list with attachment

    I'm currently trying to send out a mass email with a pdf. attachment to a list of names and associated email addresses I have in excel. I have VBA code which will allow me to send the email out but I'm having trouble finding the proper code for adding a pdf. attachment to the email.

    I'm also currently just using plain text for my signature (removed the actual signature before posting here) but would like to be able to pull my outlook signature I have saved on my comp and insert that.

    If anyone can help me out I would really appreciate it.

    Here's the code I'm currently using.

    Private Declare Function ShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
    ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long
    Sub SendEMail()
    Dim Email As String, Subj As String
    Dim Msg As String, URL As String

    Dim r As Integer, x As Double
    For r = 1 To 100 'data in rows 1 - 100
    ' Get the email address
    Email = Cells(r, 2)

    ' Message subject
    Subj = "Rev1 Power Services"

    ' Compose the message
    Msg = ""
    Msg = Msg & "Dear " & Cells(r, 1) & "," & vbCrLf & vbCrLf
    Msg = Msg & "I am with (My Company). We Specialize in hard to find, highly qualified contract personnel, such as turbine technical advisors, controls engineers, project managers, schedulers, etc., as well as the more common disciplines. We also maintain a large pool of navy nuclear trained entry level personnel." & vbCrLf & vbCrLf
    Msg = Msg & "(My Company) operates with a minimal overhead, so we can provied someo of the most competitive rates in the industry, while maintaining a tight focus on quality of service on all projects served." & vbCrLf & vbCrLf
    Msg = Msg & "Current clients include American Electric Power, Dominion Power, Florida Power and Light, Consolidated Edison, Silicon Valley Power, Worley Parsons, URS Group, Washington Gropu Iinternational, Shaw Group, Tampa Electric Company, Santee Cooper, CH2M Hill, and many others." & vbCrLf & vbCrLf
    Msg = Msg & "Additional information can be found via our website at (company website) and in the brochure I have attached to this email. I look forward to hearing back from you and hopefully my company can be of service to you in the timely and successful completion of your current and upcoming projects." & vbCrLf & vbCrLf & vbCrLf

    Msg = Msg & "Sincerely" & vbCrLf & vbCrLf
    Msg = Msg & ("Signature") & vbCrLf



    ' Replace spaces with %20 (hex)
    Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20")
    Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20")

    ' Replace carriage returns with %0D%0A (hex)
    Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A")
    ' Create the URL
    URL = "mailto:" & Email & "?subject=" & Subj & "&body=" & Msg

    ' Execute the URL (start the email client)
    ShellExecute 0&, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus

    ' Wait two seconds before sending keystrokes
    Application.Wait (Now + TimeValue("0:00:02"))
    Application.SendKeys "%s"
    Next r
    End Sub

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Creating email from excel list with attachment

    Does the pdf exist or does it need creating?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    01-11-2010
    Location
    Brandon, FL
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Creating email from excel list with attachment

    It exists and is stored in a folder under My Documents (windows xp).

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Creating email from excel list with attachment

    You should be able to adapt Ron de Bruin's code

  5. #5
    Registered User
    Join Date
    01-11-2010
    Location
    Brandon, FL
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Creating email from excel list with attachment

    Awesome, that worked, thanks.

  6. #6
    Registered User
    Join Date
    07-25-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Creating email from excel list with attachment

    Hi

    Is there any chance you could post up the code you are now using that works?

    Would literally save my life!

    Many thanks

+ 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