+ Reply to Thread
Results 1 to 5 of 5

VBA for attaching multiple files to mails

  1. #1
    Registered User
    Join Date
    10-06-2003
    Location
    Ashford, Kent - Working in London
    MS-Off Ver
    Office 365
    Posts
    95

    VBA for attaching multiple files to mails

    I've been using Ron De Bruin's excellent code for mass mailings from Outlook via Excel for some time (See http://www.rondebruin.nl/sendmail.htm - Thanks Ron!) and I'm using the specific code '.Attachments.Add (addthisfile)' to add an attachment, where 'addthisfile' is the path to the file specified in a cell in the worksheet.
    It works very well, but I now need to add two attachments and need the user to be able to enter both file paths and names in the same cell in the worksheet. Any idea what the syntax might be for this please?

    h:\text.ppt works fine when entered into the cell without any other code. If I also want to send h:\test2.doc, what code should I use?

    Thanks in advance for your help.

    Chris.
    Big Chris

  2. #2
    Registered User
    Join Date
    06-12-2008
    Location
    Newbury
    MS-Off Ver
    Office 365 ProPlus
    Posts
    92
    You could use an array.

    Add a special character, e.g. ~,#,| etc. between the filenames then use the split function to create an array of attachment paths

    So if Cell A1 = "h:\test2.doc|h:\text.ppt"

    You would then have something like this:

    Please Login or Register  to view this content.
    Last edited by chergh; 07-03-2008 at 09:44 AM.

  3. #3
    Registered User
    Join Date
    10-06-2003
    Location
    Ashford, Kent - Working in London
    MS-Off Ver
    Office 365
    Posts
    95

    Hmmmm - must be doing something wrong?

    Thanks for your help Chergh - can't get it working though

    I'm using the text as you say...
    Please Login or Register  to view this content.
    ...and have also try various options such as substituting 'Range("J2")' (which is where the files names and paths are - separated by #) to Range(attachments) where 'attachments' is defined as being the contents of J2.

    The files work individually - as always, so the paths and names are correct.

    Any other thoughts please?

    Thanks again,

    Chris.
    Last edited by VBA Noob; 07-04-2008 at 07:13 AM.

  4. #4
    Registered User
    Join Date
    06-12-2008
    Location
    Newbury
    MS-Off Ver
    Office 365 ProPlus
    Posts
    92
    Use:

    Please Login or Register  to view this content.
    To help debug and make sure the correct values come out of the array.

    Also my original code isn't complete. The attachments.add bit was only meant to illustrate where to place your attachment code.

    If you still have issues post the code you are using and include the error messages that are being generated.

  5. #5
    Registered User
    Join Date
    01-01-2014
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: VBA for attaching multiple files to mails

    You can add path in different column and use below code. With this you can add multiple attachments

    .Attachments.Add Cells(I, 8).Value
    .Attachments.Add Cells(I, 9).Value
    .Attachments.Add Cells(I, 10).Value
    .Attachments.Add Cells(I, 11).Value

+ 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