+ Reply to Thread
Results 1 to 9 of 9

Create emails and attach several attachments

  1. #1
    Registered User
    Join Date
    07-20-2016
    Location
    Norway
    MS-Off Ver
    MS Office 2013
    Posts
    4

    Create emails and attach several attachments

    Hello,

    I want to create an email and attach several attachments from a path based on a criteria using VBA.

    I have a list of unique codes in column F and the following email in column H.

    Capture.PNG

    I also have several files all stored int he following path: "C:\Users\Username\Desktop\TestFolder". All files end with an unique five digits code to the right. See below:

    - Project Brown 11111.xlsx
    - Project Red 22222.xlsx
    - Project Green 11111.xlsx
    - Project Blue 11111.xlsx

    I want the code to look for the unique five digit value and for each unique code create an email and attach all files with the same unique code.

    I have tried with the code below, but it only attachs one file to each mail.

    Can anyone help me?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Create emails and attach several attachments

    Hi, welcome to the forum.
    As your code goes, there is only ONE attachment per mail in your table.
    Please be alittle more specific,
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    07-20-2016
    Location
    Norway
    MS-Off Ver
    MS Office 2013
    Posts
    4

    Re: Create emails and attach several attachments

    Thank you for you rapid response.

    I will try to be more specific. I`m trying to get my code to go through my table where I can only find unique values and attach files from a folder based on the unique value.

    Example, the first value in column F is "11111."

    I then want my code to go through the files and add all files which contains the unique value. In this example I want the code to add 3 attachments (Project Brown, Green and Blue).

    - Project Brown 11111.xlsx
    - Project Red 22222.xlsx
    - Project Green 11111.xlsx
    - Project Blue 11111.xlsx

    Is this sufficient?

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Create emails and attach several attachments

    Please Login or Register  to view this content.
    something like this?

    ps .display would be better than .save when testing the code i would have thought
    Last edited by humdingaling; 09-25-2017 at 04:14 AM. Reason: change i = 2 instead of 1...as 1 would be your header row
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  5. #5
    Registered User
    Join Date
    07-20-2016
    Location
    Norway
    MS-Off Ver
    MS Office 2013
    Posts
    4

    Re: Create emails and attach several attachments

    Hi,

    Thank you for this, much appreciated

    This is almost what I need. I found some challenges. When I tried the code it only attached files to the first of my unique values (Value: "11111").

    I have three unique values where two of them have files I want to attach.

    "11111" = 3 files
    "22222" = 1 file
    "33333" = 0 files (Prefferably no mail generated)

    The code creates 4 emails but only one of them contains attachments(only code "11111" get the files attached, Brown, Green and Blue". Attachment "Project Red 22222.xlsx" tounique code "22222" is therefore missing.

    - Project Brown 11111.xlsx
    - Project Red 22222.xlsx
    - Project Green 11111.xlsx
    - Project Blue 11111.xlsx

    Do you have a workaround?

    I see from your code that it creates an email and then start searching for the attachments. Is it possible to create a code that closes the email doesn`t include any attachments?

    Thank you for the .display tips. Very helpful.
    Last edited by Pederpa; 09-25-2017 at 06:33 AM.

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Create emails and attach several attachments

    Just skip that part of the code

  7. #7
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Create emails and attach several attachments

    put in code to reset the loop for filenames

    rearranged the code to do filenames first
    added "chk" boolean to check if email is required


    Please Login or Register  to view this content.
    changes should be easy to follow, let me know if anything requires additional explanation
    Last edited by humdingaling; 09-25-2017 at 09:53 PM.

  8. #8
    Registered User
    Join Date
    07-20-2016
    Location
    Norway
    MS-Off Ver
    MS Office 2013
    Posts
    4

    Re: Create emails and attach several attachments

    Thank you, this works perfectly. Much appreciated!

  9. #9
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Create emails and attach several attachments

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. Using .attachments.add to attach an excel file to an outlook email
    By mirandajean in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-19-2017, 11:48 AM
  2. Macro to create emails, attach files, add recipient and add subject line
    By dw_22801 in forum Outlook Programming / VBA / Macros
    Replies: 8
    Last Post: 05-08-2017, 05:11 PM
  3. Send multiple emails with different attachments if attachments found
    By AnkitJain in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-05-2015, 05:35 AM
  4. [SOLVED] Loop Through Folder, Create Emails with Sub Folder Names in Subject, Attach files in sub
    By Rschwar23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2015, 10:06 AM
  5. How to add a box that allow to attach attachments in excel
    By tharindudk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-10-2013, 01:38 AM
  6. Delete attach in mange attachments
    By trumpetman in forum Suggestions for Improvement
    Replies: 7
    Last Post: 09-16-2013, 06:47 AM
  7. [SOLVED] Need Macro that will create & send emails w/ attachments from a list in Excel
    By rollerden in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-22-2012, 07:02 PM

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