+ Reply to Thread
Results 1 to 2 of 2

Loop Search for PDF file in folder

  1. #1
    Registered User
    Join Date
    08-12-2009
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2007
    Posts
    53

    Loop Search for PDF file in folder

    Hello, Im using a small macro that searches for a file in a particular folder. It searches for the Drive letter (as this can change) and uses the active cell as the file name, see below:
    Please Login or Register  to view this content.
    The problem I have is it turns out that there could be more than file with the same name, just numbered in order e.g. 1 to 10. Could someone please help me create a loop so it checks for the file name+number untill it finds the latest file? Or is there someway of opening the file that contains the active cell as part of the file name, but opens the newest one based on date?
    Im not very good with loops, have tried but failed misserably!
    All help much appreciated.
    Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Loop Search for PDF file in folder

    Try this:
    Please Login or Register  to view this content.
    As a simplification, the code uses the Like operator with the * wildcard character, to find files matching "THE_FILE *.PDF", so it will find files matching "THE_FILE 1234.PDF", "THE_FILE ABC XYZ.PDF", etc. if these exist in the folder, as well as the file names you describe: "THE_FILE 1.PDF", "THE_FILE 2.PDF", etc. Notice the space in " *.pdf" in the code; remove this space if the file names are "THE_FILE1.PDF", "THE_FILE2.PDF", etc. - your post doesn't describe the file names precisely enough.
    Last edited by Chippy; 10-01-2012 at 02:21 PM.
    Post responsibly. Search for excelforum.com

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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