+ Reply to Thread
Results 1 to 11 of 11

Attach multiple files to email

  1. #1
    Registered User
    Join Date
    12-31-2015
    Location
    Barreiro, Portugal
    MS-Off Ver
    MS Office 365
    Posts
    84

    Attach multiple files to email

    Hello all,

    I am trying to do a macro that (1) will create an email, (2) fill the email body with a range from the workbook, (3) save two worksheets as new workbooks and attach them to the email, (4) and then also attach all of the (pdf) files in a specific folder. My problem is with the attachment of the files (step 4, not the ones that are workbooks, I can attach those).

    When I try to do a "for each", or a while or a loop, either it attaches only one of the files, or it attaches the same file over and over again.

    Please see my code below:
    Please Login or Register  to view this content.
    Thank you for your help,
    Rui

  2. #2
    Forum Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: Attach multiple files to email

    Good morning Rui Farinha

    Just use :
    Please Login or Register  to view this content.
    You don't need the part you have highlighted in red.

    HTH

    DominicB

  3. #3
    Registered User
    Join Date
    12-31-2015
    Location
    Barreiro, Portugal
    MS-Off Ver
    MS Office 365
    Posts
    84

    Re: Attach multiple files to email

    Thank you for your reply DominicB,

    But with that how can I attach all the PDFs in the folder?

    I am attaching the workbooks fine, which seems it is what you are suggesting.

    The code in red in simply what I found relevant to do the "For each" and attach all the PDFs in folder.

    Regards,
    Rui

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,626

    Re: Attach multiple files to email

    Rui

    All this code will do is put the path and the filename of the first pdf in the folder into the variables pdfpath and pdffile.
    Please Login or Register  to view this content.
    If you want to attach all the pdfs in the folder that pdfpath points to try something like this.
    Please Login or Register  to view this content.
    Last edited by Norie; 03-26-2018 at 10:26 AM.
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    12-31-2015
    Location
    Barreiro, Portugal
    MS-Off Ver
    MS Office 365
    Posts
    84

    Re: Attach multiple files to email

    Hi Norie.

    Thank you but it still only attaches that first pdf (the only change to your code Is that I closed the parenthesis wile defining the fpdfile variable).

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,626

    Re: Attach multiple files to email

    What exactly did you try?

  7. #7
    Registered User
    Join Date
    12-31-2015
    Location
    Barreiro, Portugal
    MS-Off Ver
    MS Office 365
    Posts
    84

    Re: Attach multiple files to email

    I changed the:

    Please Login or Register  to view this content.
    To:
    Please Login or Register  to view this content.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,626

    Re: Attach multiple files to email

    You didn't bother with this line then?
    Please Login or Register  to view this content.
    That's kind of important as it gets the ball rolling on getting all the pdfs from the folder.

  9. #9
    Registered User
    Join Date
    12-31-2015
    Location
    Barreiro, Portugal
    MS-Off Ver
    MS Office 365
    Posts
    84

    Re: Attach multiple files to email

    I am sorry Norie, but since I already had the variable defined like that, I did not understood where to put it.

    Can you please clarify where is the correct place in the code?

    Also, do I keep the variable "pdfpath" defined the way it is?

    Thank you for your help

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,626

    Re: Attach multiple files to email

    Rui

    Try replacing this.
    Please Login or Register  to view this content.
    with this.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    12-31-2015
    Location
    Barreiro, Portugal
    MS-Off Ver
    MS Office 365
    Posts
    84

    Re: Attach multiple files to email

    It works! (Although it seems you duplicated the pdffile variable, I tested both ways)

    Just to understand it better, having the variable defined outside the outmail means the result would be static, but inside makes the result dynamic, is that it?

    Thank you very much for your help.

+ 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. list of files to attach in email
    By michelleblanc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-14-2018, 09:30 AM
  2. Attach files created by macro to an email
    By JesseSingh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-04-2016, 12:12 AM
  3. Add Vba to attach multiple files to outgoing email
    By bdouglas1011 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-11-2014, 11:59 AM
  4. Attach multiple files to an email
    By startuga in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-06-2014, 02:18 PM
  5. Excel Email Macro - HELP! - Need to be able to attach two different files
    By benwahchang in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-29-2013, 08:41 AM
  6. Application.GetOpenFilename, Attach files to Email, Move files, Delete Original.
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2009, 12:11 AM
  7. Modifing code to attach files to email
    By jat82nd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-20-2007, 01:41 PM

Tags for this Thread

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