Results 1 to 7 of 7

VBA to search files within a folder for a specific string and return file name

Threaded View

  1. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,346

    Re: VBA to search files within a folder for a specific string and return file name

    Welcome to the forum.

    I assumed that you meant to find the word in the filename only - searching the contents of the file is a different task: not difficult, just different.

    Copy this macro into a standard codemodule in a macro-enabled workbook, save the workbook with this macro in the folder of interest, type the word in cell A1 and run the macro.

    Sub FindWordInFileName()
        Dim strPath As String
        Dim strWFile As String
        Dim rc As Range
        
        Application.DisplayAlerts = False
        
        Range("B:B").ClearContents
        
        Set rc = Range("B1")
    
        strPath = ThisWorkbook.Path & "\"
        strWFile = Dir(strPath & "*" & Range("A1").Value & "*")
        Do While strWFile <> ""
            rc.Value = strWFile
            Set rc = rc(2)
            strWFile = Dir()
        Loop
    
    End Sub
    Last edited by Bernie Deitrick; 06-03-2014 at 01:30 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Search for a string on all excel files inside a ZIp folder
    By Moreno20 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-02-2014, 03:45 PM
  2. Want to search for string in list of files in a folder
    By DeepthiReddy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-27-2012, 03:21 AM
  3. Case insensitive search for string within folder of excel files
    By vba_novice in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-22-2011, 11:21 PM
  4. search a folder and return the most recent file's name
    By Pink_Mtl in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 05-07-2010, 04:13 PM
  5. Search files in folder based on search string
    By djvice in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-22-2008, 01:12 AM

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