![]() |
Reading Directories
Hi,
I would like to be able to loop through files within a given directory and return the name of the files from within VBA Excel. The file types within the directory will be mixed, however they will be mainly text files. I am not sure if this is possible. I hope that my question makes sense. TIA. Regards Steven |
Reading Directories
One way of several. You can restrict file type such as *.xls
Sub GetFileList() Dim ThePath As String Dim fname As String Dim i As Long ThePath = "c:\A" 'ThisWorkbook.Path fname = Dir(ThePath & "\*.*") i = 1 Do While fname < "" On Error Resume Next Cells(i, "a") = fname 'MsgBox fname On Error GoTo 0 fname = Dir() i = i + 1 Loop End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "STe" wrote in message ... Hi, I would like to be able to loop through files within a given directory and return the name of the files from within VBA Excel. The file types within the directory will be mixed, however they will be mainly text files. I am not sure if this is possible. I hope that my question makes sense. TIA. Regards Steven |
Reading Directories
Thank you Don! That is a great help.
"Don Guillett" wrote: One way of several. You can restrict file type such as *.xls Sub GetFileList() Dim ThePath As String Dim fname As String Dim i As Long ThePath = "c:\A" 'ThisWorkbook.Path fname = Dir(ThePath & "\*.*") i = 1 Do While fname < "" On Error Resume Next Cells(i, "a") = fname 'MsgBox fname On Error GoTo 0 fname = Dir() i = i + 1 Loop End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "STe" wrote in message ... Hi, I would like to be able to loop through files within a given directory and return the name of the files from within VBA Excel. The file types within the directory will be mixed, however they will be mainly text files. I am not sure if this is possible. I hope that my question makes sense. TIA. Regards Steven |
All times are GMT +1. The time now is 10:14 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com