ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Reading Directories (https://www.excelbanter.com/excel-programming/406035-reading-directories.html)

STe

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

Don Guillett

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



STe

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




Don Guillett

Reading Directories
 
Glad to help

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"STe" wrote in message
...
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