File names list

Closed
Aslam - Sep 29, 2011 at 12:53 AM
 Aslam - Oct 21, 2011 at 04:14 PM
Hello,

I will be very thankful to the person who can help me in solving of following:

I have a folder containing 1000's of files, each file have a product list of different producer. Some time I need to search a specific product in all files and list down the name of files manually. I am using "Total Commander" software to search the word or product in all files of folder, when its shows the result, I list down the files names it mentioned as result.

I need a macro in Excel which can help me in preparing the list of file names containing the search word automatically.

I would like to request you to please help me in solving this problem.

Thank you,


1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Sep 29, 2011 at 08:55 AM
Hi Aslam,

What do you mean by "preparing the list of file names"?

Best regards,
Trowa
0
Dear TrowaD,

Thank you for your reply.

I mean by " Preparing the List of file names" that when search command find the word which I am searching, the macro copy just the file name containing that word and past it in a Excel sheet.

e.g. I am searching a word "Mango" so, the macro search it in all files of specified folder and copy the name of each file containing this word and past them in a worksheet step by step.
0
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Oct 4, 2011 at 09:55 AM
Thanks for clearifying Aslam.

Try this code:

Sub FindWordDisplayFiles()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook
Dim sWhat As String
Dim r As Range
Dim x As Integer

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False

sWhat = InputBox("Find what?")

On Error Resume Next
    Set wbCodeBook = ThisWorkbook
        With Application.FileSearch
            .NewSearch
            'Change path to suit
            .LookIn = "C:\MyDocuments\TestResults"
            .FileType = msoFileTypeExcelWorkbooks
                If .Execute > 0 Then
                    For lCount = 1 To .FoundFiles.Count
                        Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
    
    Set r = Cells.Find(What:=sWhat, LookAt:=xlPart)
    If Not r Is Nothing Then
            'Change destiantion file to suit and make sure it's not in same folder as path above
            Workbooks("Destination.xls").Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = ActiveWorkbook.FullName
    End If

                        wbResults.Close SaveChanges:=False
                    Next lCount
                End If
        End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

Best regards,
Trowa
0
Dear Trowad,

I really appreciate your efforts!!!!!!!!!!!!!

I am sorry I think I have not informed you that the folder contains files of Ms Word not of Ms Excel. the search command have to search in Ms Words files.

Therefore kindly alter it and enable it to find the word in MS Word files.

Furthermore, please add a message which confirm that the work has completed.

Thank you once again for your help

Aslam
0
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Oct 6, 2011 at 09:25 AM
Sorry Aslam, this is where my knowledge ends. I don't like Word, I basically do everything in Excel because it's much easier to understand (at least for me).

Let me ask someone with more knowledge to see if he can solve your query.

Best regards,
Trowa
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Oct 6, 2011 at 07:42 PM
Gee Trowa, you are one amazing person. Taking time to help some one is one thing, but going beyond to look for someone else is extremely out of this world attitude. Thanks for being such a person.

Aslam, I have not heard of this software. If http://www.ghisler.com/efaqfile.htm#printlist link is related to this software, it seems that you can copy the file names to some external file etc. Could you see the link and see if that works out. If the names of the files can be some how copied out into a one file, then managing that one file would be simple (I think)
0