PDA

View Full Version : input the names of all MS Word file in an Excel file.



clarksonneo
06-22-2011, 06:18 AM
Hi,


There are a number of MS Word files in a fold.
I want to input the names of all MS Word files in an Excel file.
I want to input them on coulmn A.


Could you please write me the Excel Macro that can perform the above task?

Thanks

Bob Phillips
06-22-2011, 06:49 AM
Dim FSO As Object
Dim fldr As Object
Dim file As Object
Dim i As Long

Set FSO = CreateObject("Scripting.FileSystemObject")
Set fldr = FSO.getfolder("C:\test")
Range("A1").Value = "Filename"
i = 1
For Each file In fldr.Files

If file.Type Like "*Microsoft Word*" Then

i = i + 1
Cells(i, "A").Value = file.Name
End If
Next file

Set file = Nothing
Set fldr = Nothing
Set FSO = Nothing