+ Reply to Thread
Results 1 to 9 of 9

vba to search for a word in files in a directory

  1. #1
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    vba to search for a word in files in a directory

    Hi

    I have seen several examples of VBA to find files by file name or property, but is if possible to use VBA to search all files (not just excel) in a directory to find a particular word or phrase in the file?

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: vba to search for a word in files in a directory

    Hello NickyC,

    Yes, you can. Depending on the number of files, their size, and number of words you are looking for it could take quite awhile to finish.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: vba to search for a word in files in a directory

    Thanks Leith
    could you point me to the VBA commands (filesearch apparently no longer works)
    or.. is it necessary to open each file to search it?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: vba to search for a word in files in a directory

    Hello NickyC,

    What type of files do you want to examine?

  5. #5
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: vba to search for a word in files in a directory

    Hi Leith
    both word and excel files, if possible.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: vba to search for a word in files in a directory

    Hello NickyC,

    The files would need to be opened to search them. Searching Word isn't too difficult. Would you be searching a specific sheet or sheets in Excel or all sheets within a workbook?

  7. #7
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: vba to search for a word in files in a directory

    Hi Leith

    I was really hoping to create a dialog box that would reproduce the functionality of the old search box in windows many years ago – when a single box allowed you to specify which directories to search, whether to search subdirectories, file names or partial file names, file types, words or whole phrases in documents, date created, file size etc. I can manage most of this because the search items are file properties, but was hoping for something equivalent to the “search in file contents” command

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: vba to search for a word in files in a directory

    Hello NickyC,

    I remember that dialog. I think it phased out of Windows with the release of Windows 2000. That is when Windows made the transition from FAT to NT file format. Unfortunately, I don't know of replacement for that dialog. Perhaps another member has some information that will help you.

  9. #9
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: vba to search for a word in files in a directory

    Thanks Leith for your comments

    I may try to create a dialog box based on your suggestion of opening files, and stick to using it one directory at a time.

    It's another on the long list of useful features that Windows (doubtless for good reasons) has withdrawn over the years. I still pine for the capcity to record macros in PowerPoint, too!

+ 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. VBA directory search for files stored on mac & in subfolders
    By thebute in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2014, 04:02 AM
  2. Search for files in directory and subdirectories using wildcard
    By modytrane in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2013, 10:13 AM
  3. Search For Directory and All Subdirectories for Files using wildcard
    By modytrane in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-28-2012, 11:49 AM
  4. Replies: 1
    Last Post: 05-03-2011, 01:22 PM
  5. search directory, list files containing certain txt
    By mikeyfear in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-29-2008, 08:06 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