Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Clear the file open file name dropdown list | Excel Discussion (Misc queries) | |||
File list - list filenames in excel | Excel Programming | |||
ActiveSheet.QueryTables.Add using InputBox and/or a URL list in a .txt file list | Excel Programming | |||
The 'Recently used file list' does not show up under the 'File' menu. | Excel Worksheet Functions | |||
Convert List box from excel file to VBA list box object | Excel Programming |