+ Reply to Thread
Results 1 to 4 of 4

VBA to retrieve the file path from ANY drive by inputting whole or part of a filename.

Hybrid View

  1. #1
    Registered User
    Join Date
    07-31-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    2

    VBA to retrieve the file path from ANY drive by inputting whole or part of a filename.

    Hi,
    I am trying to work on a problem to make the operations simpler at the organization.
    I want to enter whole or part of a filename and want to receive the file path for all files that match the substring I enter. The program should search through all the hard drive files (even subfolders) and network files.

    For example:

    I type in cell A1: "7556"
    Output in B1: "7556N0142 folder path F:\Drawings\released drawings\7556N0142"
    B2: "7556N0136 folder path F:\Drawings\released drawings\7556N0136"

    Any help will be greatly appreciated. I have worked on a lot of programs in excel in the past but this is too complex for me. I belong to mechanical engineering background but I can understand the algorithms and logics easily.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,924

    Re: VBA to retrieve the file path from ANY drive by inputting whole or part of a filename.

    VBA isn't the best tool for this, though it can be done through use of DIR function and recursively looping through each and every folder.

    You will find many examples in link below.
    http://www.exceltrick.com/formulas_m...-dir-function/

    Alternately, you could use WScript.Shell to run findstr command. See link for detail on findstr.
    https://www.computerhope.com/findstr.htm

    Read below on how to get the output from WScript.Shell.
    https://stackoverflow.com/questions/...specific-shell

    However, in all instances, it is recommended you limit scope (to specific folder), in order to limit code run time.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    07-31-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    2

    Re: VBA to retrieve the file path from ANY drive by inputting whole or part of a filename.

    Thanks a lot for the help and suggestions. I will try it out. Also, a bit off topic but except excel VBA what other programming/tools can I use to solve this problem. I can learn the programming language required to do this.

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,924

    Re: VBA to retrieve the file path from ANY drive by inputting whole or part of a filename.

    Few that comes to mind are...
    Windows PowerShell
    Windows Command Line (batch file)
    GREP

    I prefer Command line (batch file) to output result into text file.

    You can then read that file into Excel.

+ 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. web query in Macro - how to embedded in file, not a path to c Drive
    By asyahdo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-14-2013, 01:49 AM
  2. [SOLVED] How to retrieve part of a filename?
    By jonelamora in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-03-2012, 04:25 AM
  3. Find File Path to USB Drive
    By andyrads in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-15-2009, 05:32 PM
  4. Windows API to Determine if File is Local/Convert Path to Drive Letter
    By Johnny in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-10-2006, 09:30 AM
  5. macro to retrieve path to opened file
    By windsurferLA in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-18-2005, 10:06 AM
  6. Reflect file path (show drive letters) in Excel 2000
    By Alicia in forum Excel General
    Replies: 4
    Last Post: 01-20-2005, 03:06 PM

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