Make a file list using Excel

Glen Charles Rowel

New Member
Joined
Oct 11, 2004
Messages
44
What formula can I paste into Excel to have all the files in a folder (eg c:\in here) listed. Most of the files are TXT and HTML.

Thanks

Regards,

Glen Charles Rowell
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Glen

As far as I know this wouldn't be possible using formulae - you would need to use VBA.

Is that what you are looking for?

Something like this perhaps:

Code:
Sub ListTxtAndHTML()
Dim I As Integer
    ActiveSheet.Range("A1:B1") = Array("Text", "HTML")
    
    With Application.FileSearch
        .NewSearch
        .LookIn = "C:\Papers\"
        .Filename = "*.txt*"
        .Execute
        
        For I = 1 To .FoundFiles.Count
            ActiveSheet.Range("A" & (I + 1)) = .FoundFiles(I)
        Next
    End With
 
    With Application.FileSearch
        .NewSearch
        .LookIn = "C:\Papers\"
        .Filename = "*.htm*"
        .Execute
        
        For I = 1 To .FoundFiles.Count
            ActiveSheet.Range("b" & (I + 1)) = .FoundFiles(I)
        Next
    End With
End Sub
 
Upvote 0
Glen said:
Do I just copy that into a cell?
No

If you really want to use it open the VBE with Alt+F11.

Then goto Insert>Module and paste the code there.

You can then run it using various methods, one of which is, from Excel, Tools>Macro...>Macros...
 
Upvote 0
Glen

I thought you might ask that.

What version of Excel are you using?

With Excel 2000 you could try this:
Code:
Sub ListTxtAndHTML()
Dim I As Integer
    ActiveSheet.Range("A1:B1") = Array("Text", "HTML")
    
    With Application.FileSearch
        .NewSearch
        .LookIn = "C:\Papers\"
        .Filename = "*.txt*"
        .Execute
        
        For I = 1 To .FoundFiles.Count
            ActiveSheet.Range("A" & (I + 1)) = Mid(.FoundFiles(I), InStrRev(.FoundFiles(I), "\") + 1)
        Next
    End With

    With Application.FileSearch
        .NewSearch
        .LookIn = "C:\Papers\"
        .Filename = "*.htm*"
        .Execute
        
        For I = 1 To .FoundFiles.Count
            ActiveSheet.Range("b" & (I + 1)) = Mid(.FoundFiles(I), InStrRev(.FoundFiles(I), "\") + 1)
        Next
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,327
Messages
6,124,276
Members
449,149
Latest member
mwdbActuary

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