+ Reply to Thread
Results 1 to 31 of 31

Find files in folder where part of file name match Range and attach to Mail.

  1. #1
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Find files in folder where part of file name match Range and attach to Mail.

    Hi All

    So, if the macro below finds a "Yes" in
    Please Login or Register  to view this content.
    and the value in that range is "1234" for instance then i want all files in the specified folder where the file name contains 1234 to me attached to the mail.

    So even if the file name is "what a good 1234 day it is", that will be attached to the mail as it contains 1234.

    There are PDF and Excel files in the folder.

    Please Login or Register  to view this content.
    Thanks in advance for any help.
    Last edited by ANDREAAS; 06-12-2020 at 03:41 PM.
    A great big thank you to all the experts on the forum that are always so friendly and helpful.

    You guys Rock!!!!

  2. #2
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    Hi All

    Ok, so i found the macro below which looks like it might work, but i do not know how to incorporate it into my original macro that creates the mail.
    Also on the macro below, the file type is defined as PDF and i would like for the macro to search for PDF as well as XLS & XLSM.

    The part in red needs to be variable to fit with the original code(i think this would be something like
    Please Login or Register  to view this content.
    ?)

    Any help would be much appreciated. Thanks in advance!

    Please Login or Register  to view this content.

  3. #3
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Find files in folder where part of file name match Range and attach to Mail.

    Incorporate this...
    Please Login or Register  to view this content.
    I am guessing this thread HERE is somehow connected...
    Last edited by sintek; 06-13-2020 at 10:54 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  4. #4
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    Hi sintek

    Yes they are connected, i just like to split the different questions up into separate parts to try make it easier for members searching for specific info.

    Thank you very much. Will check out the code a bit later and let you know how it goes before i mark this solved.

  5. #5
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    Hi @sintek

    So the code you provided works perfectly, but i am still stuck in an infinite loop and can't figure out why.

    Below is the final code(with the loop error) if anyone is interested.

    The code seems to never stop running and if i hit ESC then it debugs to this part :
    Please Login or Register  to view this content.
    Any ideas?

    Final Code(with loop error) :
    Please Login or Register  to view this content.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Find files in folder where part of file name match Range and attach to Mail.

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    Awesome! Works perfectly thank you very much.

    One last thing if i may.......

    It's not the same files that are sent the whole time(forgot to mention, so i tried this :
    Please Login or Register  to view this content.
    ,but that does not work....

    any ideas?

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Find files in folder where part of file name match Range and attach to Mail.

    What is the value in cells(cell.row,"Q")...Does it include the extensions...Does it include a wildcard character "*"

    Uploading a sample file depicting your actual files setup is always important...That way members can assist with actual code and not have to guesstimate...
    Last edited by sintek; 06-14-2020 at 10:21 AM.

  9. #9
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    the values will always be a number 4 to 8 digits and on occasion be preceded with a letter or 2 like QU.

    busy creating a separate sheet to upload, will do so shortly....my original is waaaaaay too large to upload even if i do clean it up it.

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Find files in folder where part of file name match Range and attach to Mail.

    Please Login or Register  to view this content.
    check the value of each of the above as follows...
    Just before the statement put
    Please Login or Register  to view this content.
    This will depict the two values...
    The like parameter searches a wildcard comparison... Which the two above will never have as the file extension is not included in your statement...

    As per post 3...
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    Hi

    See attached as requested.
    Attached Files Attached Files

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Find files in folder where part of file name match Range and attach to Mail.

    the values will always be a number 4 to 8 digits and on occasion be preceded with a letter or 2 like QU.
    You are confusing us now...Column Q has Yes or No...So are you trying to search for files with Yes or No names???

  13. #13
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    No, it searches for rows with Yes/No to determine opening a new mail or not and then searches the Offset value in Column P for the file to attach.

    i.e. if there is yes in column P then create a new mail with the files of the "like" name in the same row in column p attached to that mail.
    Last edited by ANDREAAS; 06-14-2020 at 01:57 PM.

  14. #14
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Find files in folder where part of file name match Range and attach to Mail.

    So why this in your code
    Please Login or Register  to view this content.
    this indicates file name as per Column Q

  15. #15
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    dummy mistake

    should be
    Please Login or Register  to view this content.
    thanks for pointing that out.

  16. #16
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    sorry for the confusion

  17. #17
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Find files in folder where part of file name match Range and attach to Mail.

    You are wanting this perhaps...Untested...
    Please Login or Register  to view this content.

  18. #18
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    yes thats it.

    another mistake, i put (-1,0) above but it should be as you have it the other way around

  19. #19
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    the workbook is still giving a error though, so i don't think that i complited it correctly.

    giving me end if without break if and same with, with.

  20. #20
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Find files in folder where part of file name match Range and attach to Mail.

    Are not closing one of your condition statements...Don't have the file or code so cannot assist

  21. #21
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    hi

    i attached the file a few posts up

  22. #22
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    see attached
    Attached Files Attached Files

  23. #23
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Find files in folder where part of file name match Range and attach to Mail.

    Please Login or Register  to view this content.

  24. #24
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    still giving "next without for" here :
    Please Login or Register  to view this content.

  25. #25
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    will you perhaps attach the workbook with the corrections in and highlight the corrections?

    lol, not getting impatient....just worried i'm taking up too much of your time

  26. #26
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Find files in folder where part of file name match Range and attach to Mail.

    Oops for got the attachments add snippet...
    Please Login or Register  to view this content.
    Cannot test right now and working from lounge Pc...No Outlook
    Last edited by sintek; 06-14-2020 at 02:43 PM.

  27. #27
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    cool, will try it again a bit later and let you know.....gotto run quickly for now

    thank you very much so far sintek

  28. #28
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    Alright, so it's working now, but for some reason it changes the offset values for the body with each mail.

    So in the code, the offset values stay the same but the first mail will give the correct values for :
    Please Login or Register  to view this content.
    then the next mail that opens will show as if the code has moved one over on the offset to :
    Please Login or Register  to view this content.
    the next mail after than moves one more and so on.

    What would be the reason for that?

  29. #29
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Find files in folder where part of file name match Range and attach to Mail.

    Please Login or Register  to view this content.
    Lets assume the loop is in row 5...the above code takes the value from [D6] ... .Offset(-1, -13) means 1 row below , 13 columns to Left
    as you are looping cells in column "Q"
    this snippet
    Please Login or Register  to view this content.
    is actually
    Please Login or Register  to view this content.
    so if you want to get a value within that same row...make use of the offset values i.e.

    cell.offset(,1) means 1 column to right same row...
    cell.offset(,-1) means 1 column to left same row...
    I assume you don't want to reference cells above or below active row so the row must not be referenced in the code...

    I notice that you are wanting to reference your Headers in your Email body...make use of this snippet for that... i.e.
    Please Login or Register  to view this content.
    Last edited by sintek; 06-15-2020 at 03:15 AM.

  30. #30
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: Find files in folder where part of file name match Range and attach to Mail.

    You are awesome sintek.

    thank you very, very much!!!!!!

    I'm so happy, i'll repeat that in Klingon..... nagh SoH, qatlho'qu'

  31. #31
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Find files in folder where part of file name match Range and attach to Mail.

    ..........................
    THANKS.gif

+ 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] Save a copy from attacment to a specific folder when attach a xlsx in mail
    By dodde in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-07-2020, 07:25 AM
  2. [SOLVED] Macro to attach all files in a folder
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-27-2019, 09:01 AM
  3. [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
  4. Replies: 4
    Last Post: 10-17-2014, 09:31 AM
  5. Attach files to E-mail based on partial filename
    By MUCa346 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2014, 11:24 AM
  6. Open up a Lotus Notes Database (not mail) create a new post and attach files VBA Excel
    By exceliscool in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2014, 03:25 PM
  7. [SOLVED] attach file from folder on c:\ to outlook mail and send
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-24-2013, 11:33 AM

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