+ Reply to Thread
Results 1 to 2 of 2

code for multiple attachments

  1. #1
    Registered User
    Join Date
    06-11-2012
    Location
    Cleethorpes, Englend
    MS-Off Ver
    excel 2007
    Posts
    1

    code for multiple attachments

    Please could someone help me as i'm new to vba.

    in my spreadsheet A1, A2, A3 & A4 i have got some jpeg file addresses. I need to alter the code below to attach all 4 addresses into an outlook email. If there are less than 4 I still need it attach those. e.g if there is only 1 address in A1 then I still need it to attach that.


    Sub SendMail()
    Dim oOutlook As Object
    Dim oMailItem As Object
    Dim oRecipient As Object
    Dim oNameSpace As Object
    Dim emailDate As Date
    Dim sAttachment As String



    sAttachment = Range("A1")



    Set oOutlook = CreateObject("Outlook.Application")


    Set oMailItem = oOutlook.CreateItem(0)
    With oMailItem
    Set oRecipient = .Recipients.Add("email address")
    oRecipient.Type = 1 '1 = To, use 2 for cc
    'keep repeating these lines with
    'your names, adding to the collection.
    .Subject = "Data for " & Format(emailDate, "dd mmm yyyyy")
    .Body = "This is data for " & Format(emailDate, "dd mmm yyyyy")
    .Attachments.Add sAttachment
    .Display
    End With


    End Sub

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: code for multiple attachments

    Try

    Please Login or Register  to view this content.
    Martin

+ 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