View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Gary Keramidas Gary Keramidas is offline
external usenet poster
 
Posts: 2,494
Default can someone simplify this file listing for me

this puts all the file names located in the specified folder starting in A1

Option Explicit
Sub test()
Dim lastrow As Long
Dim MyFiles() As String
Dim NumberOfFiles As Long
Dim FilesInPath As String
Dim FileDir As Variant

FileDir = "e:\plu"
lastrow = Worksheets("sheet1").Cells(Rows.Count, "A").End(xlUp).Row

FilesInPath = Dir(FileDir & "\*.fxd")
NumberOfFiles = 0
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If

Do While FilesInPath < ""

Worksheets("Sheet1").Range("A" & lastrow).Value = FilesInPath

NumberOfFiles = NumberOfFiles + 1
lastrow = lastrow + 1

ReDim Preserve MyFiles(1 To NumberOfFiles)
MyFiles(NumberOfFiles) = FilesInPath
FilesInPath = Dir()

Loop
End Sub

--


Gary