Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default List file name only

Excel XP, Win XP
I want get a listing of all the files in a specific folder (ThePath). The
following code does this but the listing includes the path before every file
name. How do I change this code to give only the file names, for instance,
FileName.xls.
Thanks for your time. Otto

Sub GetFileList()
Dim c As Integer
With Application.FileSearch
.NewSearch
.LookIn = ThePath
For c = 1 To .Execute
Dest.Value = .FoundFiles(c)
Set Dest = Dest.Offset(1)
End If
Next c
End With
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default List file name only

this will list all of the excel files in the path of the current workbook in
column A

Sub GetFileList()
Dim ThePath As String
ThePath = ThisWorkbook.Path
fname = Dir(ThePath & "\*.xls")
i = 1
Do While fname < ""
Range("A" & i) = fname
fname = Dir()
i = i + 1
Loop
End Sub



--


Gary


"Otto Moehrbach" wrote in message
...
Excel XP, Win XP
I want get a listing of all the files in a specific folder (ThePath). The
following code does this but the listing includes the path before every file
name. How do I change this code to give only the file names, for instance,
FileName.xls.
Thanks for your time. Otto

Sub GetFileList()
Dim c As Integer
With Application.FileSearch
.NewSearch
.LookIn = ThePath
For c = 1 To .Execute
Dest.Value = .FoundFiles(c)
Set Dest = Dest.Offset(1)
End If
Next c
End With
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default List file name only

Thanks Gary, I'll give that a try. Otto
"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this will list all of the excel files in the path of the current workbook
in column A

Sub GetFileList()
Dim ThePath As String
ThePath = ThisWorkbook.Path
fname = Dir(ThePath & "\*.xls")
i = 1
Do While fname < ""
Range("A" & i) = fname
fname = Dir()
i = i + 1
Loop
End Sub



--


Gary


"Otto Moehrbach" wrote in message
...
Excel XP, Win XP
I want get a listing of all the files in a specific folder (ThePath).
The following code does this but the listing includes the path before
every file name. How do I change this code to give only the file names,
for instance, FileName.xls.
Thanks for your time. Otto

Sub GetFileList()
Dim c As Integer
With Application.FileSearch
.NewSearch
.LookIn = ThePath
For c = 1 To .Execute
Dest.Value = .FoundFiles(c)
Set Dest = Dest.Offset(1)
End If
Next c
End With
End Sub





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default List file name only

I want get a listing of all the files in a specific folder (ThePath). The
following code does this but the listing includes the path before every
file name. How do I change this code to give only the file names, for
instance, FileName.xls.
Thanks for your time. Otto

Sub GetFileList()
Dim c As Integer
With Application.FileSearch
.NewSearch
.LookIn = ThePath
For c = 1 To .Execute
Dest.Value = .FoundFiles(c)
Set Dest = Dest.Offset(1)
End If
Next c
End With
End Sub


The following keeps the approach you attempted above...

Sub GetFileList()
Dim c As Integer
Dim Dest As Range
Set Dest = Range("a1")
With Application.FileSearch
.NewSearch
.LookIn = "c:\temp"
.FileType = msoFileTypeAllFiles
.Execute
For c = 1 To .FoundFiles.Count
Dest.Value = Mid$(.FoundFiles(c), _
InStrRev(.FoundFiles(c), "\") + 1)
Set Dest = Dest.Offset(1)
Next c
End With
End Sub

Rick

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default List file name only

Option Explicit

Sub GetFileList()
Dim Dest As Range
Dim c As Long
Dim ThePath As String
Dim myName As String
Set Dest = ActiveSheet.Range("a1")
ThePath = "C:\my documents\excel\"

With Application.FileSearch
.NewSearch
.LookIn = ThePath
For c = 1 To .Execute
myName = Mid(.FoundFiles(c), InStrRev(.FoundFiles(c), "\") +
1)
Dest.Value = myName
Set Dest = Dest.Offset(1)
Next c
End With
End Sub

instrrev was added in xl2k.


Otto Moehrbach wrote:

Excel XP, Win XP
I want get a listing of all the files in a specific folder (ThePath). The
following code does this but the listing includes the path before every file
name. How do I change this code to give only the file names, for instance,
FileName.xls.
Thanks for your time. Otto

Sub GetFileList()
Dim c As Integer
With Application.FileSearch
.NewSearch
.LookIn = ThePath
For c = 1 To .Execute
Dest.Value = .FoundFiles(c)
Set Dest = Dest.Offset(1)
End If
Next c
End With
End Sub


--

Dave Peterson


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
Clear the file open file name dropdown list Daniel.C[_2_] Excel Discussion (Misc queries) 8 October 23rd 08 09:47 AM
File list - list filenames in excel JRP Excel Programming 4 February 19th 07 06:38 PM
ActiveSheet.QueryTables.Add using InputBox and/or a URL list in a .txt file list crazy_vba[_5_] Excel Programming 4 April 29th 06 10:54 PM
The 'Recently used file list' does not show up under the 'File' menu. David F Excel Worksheet Functions 4 June 6th 05 07:43 AM
Convert List box from excel file to VBA list box object baha[_2_] Excel Programming 0 November 22nd 03 05:06 PM


All times are GMT +1. The time now is 03:50 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"