Find Text in folder directory

ajit80

New Member
Joined
Feb 9, 2013
Messages
45
Hello everyone,

Pls Help,

I have a folder directory (Name: "Company 2009") containing excel files:-

We want to find Name of File Containing Text "No Ceiling" and show a list of File Names having this content.

Thanking You
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,

Try this - just change the complete location of the relevant folder in red. The file names should be printed in the immediate window.

Rich (BB code):
Sub CheckFileNames()
    
    Dim fso As Object
    Dim FileToCheck As Object
    Dim FolderToCheck As Object
    Dim FolderToCheckPath As String
    
    FolderToCheckPath = "C:\Users\Documents\Excel\Company 2009\"
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    Set FolderToCheck = fso.GetFolder(FolderToCheckPath)

    For Each FileToCheck In FolderToCheck.Files
    
        If FileToCheck.Name Like "*No Ceiling*" Then
        
            Debug.Print FileToCheck.Name
            
        End If
        
    Next FileToCheck
    


End Sub
 
Upvote 0
Be aware @KKaren solution is case sensitive

it lists only "No Ceiling"
it does not list "no ceiling", "No Ceiling","No ceiling","NO CEILING" etc

This test is case sensitive
Code:
        If FileToCheck.Name Like "*No Ceiling*" Then

If you do not want the list case sensitive, here is one way to modify the test
Code:
        If [B]UCase([/B]FileToCheck.Name[B])[/B] Like "*[B]NO CEILING[/B]*" Then
 
Upvote 0
The way I read post #1 was to search for content inside the file and not as part of a file name.
 
Upvote 0
Thanks KKaren,

But code is not working. Not showing any file name which containing text "No Ceiling". I have lots of file where content (No Ceiling) inside the file.

Main Folder Directory: Company 2009
sub folders: A, B, C, ......................Z
Sub Folders contains many .xls Files.
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top