+ Reply to Thread
Results 1 to 10 of 10

Add attachment based on partial file name match

  1. #1
    Registered User
    Join Date
    05-11-2020
    Location
    England
    MS-Off Ver
    MS Office 2010
    Posts
    5

    Add attachment based on partial file name match

    Dear All,

    I hope that someone can help me with a task I need to complete very quickly. I've spent a couple of hours searching forums but cannot find exactly what I need.

    I have a folder containing several hundred pdf files which use the individual's email address at the beginning of the file name. The pdf names are as follows:

    emailaddress_COI_Report.pdf
    Folder location: N:\December\Reports

    I would like to use a macro-enabled workbook to search the folder, ignoring the last 15 characters of the file name. This should enable a match with the email addresses in sheet 1, column A, cells A2,A3, A4 etc.

    When a match is found, the specific pdf should be attached to the recipient's email message.

    I would be grateful for any advice on how to accomplish this.

    Many thanks
    halltribe
    Attached Files Attached Files
    Last edited by halltribe; 12-14-2020 at 01:17 PM. Reason: Attachments added

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Add attachment based on partial file name match

    It would be easier to help and test possible solutions if you could attach a copy of your file. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary). See the yellow banner at the top of this page for instructions to attach a file.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    05-11-2020
    Location
    England
    MS-Off Ver
    MS Office 2010
    Posts
    5

    Re: Add attachment based on partial file name match

    Thank you Mumps1. I have added attachments as you suggest.

    The Excel file has a list of email addresses in column A.

    I would like to use VBA to compare the email addresses in the workbook against the pdf names contained in the folder. The last 15 characters of each pdf name is the same - if these characters can be ignored, the email address in the pdf name should then match the email addresses contained in the workbook and be used to create the email message and attach the appropriate report only.
    Last edited by halltribe; 12-14-2020 at 01:31 PM. Reason: Further explanation

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Add attachment based on partial file name match

    Do you want the macro to generate the email for each address in column A? If so, I would need to know what you want as the subject of the email, the contents of the body of the email and the contents of the signature part of the email.

  5. #5
    Registered User
    Join Date
    05-11-2020
    Location
    England
    MS-Off Ver
    MS Office 2010
    Posts
    5

    Re: Add attachment based on partial file name match

    Thank you Mumps1. Yes, a message should be generated for each email address in column A where a PDF exists that contains a match for the email address.

    The subject could be "Declaration of Interest - Approved"

    and the body "Dear Colleague, please find attached a report containing your declaration of interest, which has been agreed by the Corporate Services team. If you have any queries, please do not hesitate to contact the undersigned"

    "Corporate Services Team
    MyCompany"
    Last edited by halltribe; 12-14-2020 at 02:12 PM.

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Add attachment based on partial file name match

    Try:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-11-2020
    Location
    England
    MS-Off Ver
    MS Office 2010
    Posts
    5

    Re: Add attachment based on partial file name match

    Thank you so much for this code Mumps1.

    I have opened my spreadsheet, created a module and pasted the code.

    I used F5 to run the code. Nothing appeared to happen, so I tried to debug by adding breakpoints. By doing so, I could see that the email addresses (values in column A) were showing correctly.

    The sval values were showing as the part of the email address before the "at" symbol. (Sorry, it won't allow me to post an "at" symbol, as I'm new).

    In order to get the code to work, I had to rename my files to match the sval. I tried again and the emails were successfully created.

    Is there any way to make a slight adjustment to the sval line of code so that the full email address is created as the string.

    Thank you for any more advice. I appreciate the time you have taken to help me.

    halltribe

  8. #8
    Registered User
    Join Date
    05-11-2020
    Location
    England
    MS-Off Ver
    MS Office 2010
    Posts
    5

    Re: Add attachment based on partial file name match

    Solved it. Changed the -1 in sval line to +50. Works perfectly now.
    Thank you.

  9. #9
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: Add attachment based on partial file name match

    Hi,

    you only needed tot change
    Please Login or Register  to view this content.
    Please be as complete as possible in your asking so it may save use all the time to rework the solution because you didn't give all the requirements. If you have a layout in mind please work it out first so we can adapt our solution to it. Thanks.
    If you have been helped, maybe you could click the *

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Add attachment based on partial file name match

    You are very welcome.

+ 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. [SOLVED] Open file and run macro based on partial file name
    By PaulM100 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-06-2019, 11:07 AM
  2. Attach File to Outlook Based on Partial Criteria file name
    By brianfu777 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-09-2019, 05:13 AM
  3. [SOLVED] VLOOKUP based on partial match
    By MetroBOS in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-03-2017, 11:58 AM
  4. Need Macro file to split then consolidate workbooks based on partial file name
    By dawnmau in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-04-2014, 04:37 PM
  5. Replies: 0
    Last Post: 09-21-2013, 09:03 PM
  6. [SOLVED] Partial string match with file name
    By jamer02 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-20-2012, 06:50 AM
  7. sumif based on partial match
    By [email protected] in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-03-2006, 08:20 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