Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
STe STe is offline
external usenet poster
 
Posts: 3
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
STe STe is offline
external usenet poster
 
Posts: 3
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sub Directories Mike H. Excel Programming 5 August 2nd 07 08:56 PM
sub directories again Shailesh Shah[_2_] Excel Programming 5 February 9th 04 09:32 PM
sub directories again Mike[_67_] Excel Programming 2 February 7th 04 12:06 AM
sub directories Mike Excel Programming 5 February 6th 04 10:15 PM
Directories Jeff[_24_] Excel Programming 4 January 20th 04 09:26 AM


All times are GMT +1. The time now is 11:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"