+ Reply to Thread
Results 1 to 9 of 9

Search for an excel workbook beginning with... in a folder and subfolders

  1. #1
    Registered User
    Join Date
    04-07-2013
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    26

    Unhappy Search for an excel workbook beginning with... in a folder and subfolders

    Hi

    I am at a loss for a code that will search for an excel workbook beginning with (whatever), in a folder and the folders sub folders, and open the file.
    I know the starting directory eg (C:\Users\)

    I am using excel 2010 and have previously used application.filesearch which no longer works.

    Any help would be appreciated.

    thanks

  2. #2
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Search for an excel workbook beginning with... in a folder and subfolders

    Hi..

    Try the attached..
    You just need to change the file path in this line.. this is the File Path that it starts looking into (and then goes into all sub folders in that)..

    Please Login or Register  to view this content.
    It works well.. but i found it had permissions issues when trying to loop through C:\Users..
    I am looking now for a fix for that..
    Attached Files Attached Files

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Search for an excel workbook beginning with... in a folder and subfolders

    @APO - that's the way to do it. I'd suggest adding an END call after the Workbook.Open call to stop the search routine.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Search for an excel workbook beginning with... in a folder and subfolders

    Hi Jerry..

    Good idea..

    Any thoughts on the Permissions issue the OP will face when he tries to make it search through C:\Users|.... folders?

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Search for an excel workbook beginning with... in a folder and subfolders

    I've used that technique many times to the very thing you're doing, never seen a permissions error.

  6. #6
    Registered User
    Join Date
    04-07-2013
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    26

    file search

    Hi APO
    Thanks for the code. I only got round to trying it out today. It works a treat. However, I was looking to add a wildcard to the file name I am searching for, as the file I search for gets updated weekly and gets a date added to the file name. Any thoughts on how to make a wildcard work whilst searching?

  7. #7
    Valued Forum Contributor Miraun's Avatar
    Join Date
    04-03-2009
    Location
    New England
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    554

    Re: Search for an excel workbook beginning with... in a folder and subfolders

    Hi Redmarko;

    For clarification, is that wildcard something that you want in Cell A1 on the worksheet, or hardcoded so that whatever string is in A1 in the worksheet needs to be in the file name?

    You can change Line 30 in Module 1 of Apo's example to:
    Please Login or Register  to view this content.
    Which should put wildcards on each side of A1 string
    Going for Guru! Click the Star to the bottom left of this post if I helped!

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Search for an excel workbook beginning with... in a folder and subfolders

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

  9. #9
    Registered User
    Join Date
    04-07-2013
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Search for an excel workbook beginning with... in a folder and subfolders

    Hi Miraun

    Thanks for the reply. I was looking to hardcode the wildcard. I am using an input box for a user to enter a string. The vba should then use this string with addition of wildcard to open file.

    regards

+ 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] list of subfolders in folder - without files and sub-subfolders
    By MartyZ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2022, 10:56 AM
  2. List All SubFolders In A Folder Excel 2013
    By PY_ in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-18-2013, 10:02 AM
  3. how to search a file in folder and subfolders
    By rakeshredround in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-05-2012, 03:35 AM
  4. Macro to search folder including subfolders for file and open
    By kiraexiled in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-01-2012, 02:45 PM
  5. Replies: 2
    Last Post: 03-26-2012, 07:12 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