Hello Matt,
Here is a macro I wrote a little while ago because I needed to keep better track of my files. You can select the file type to list and do wild card matching on the file names. Copy this code into a standard module in the workbook "Processed Orders.xls". Add a button to the worksheet "Processed Orders" and attach the macro "ListFiles" to it. Here is the code...
'Written: February 19, 2009
'Author: Leith Ross
'Summary: Creates a file list and copies it to the Active Sheet start at "A1".
' The arguments are the directory to be searched, the file type (extension),
' and optionally a wildcard filter for file names. Only the rquired argument
' is the directory path.
Function CreateFileList(ByVal FolderPath As String, Optional ByVal FileType As String, Optional ByVal FileFilter As String) As Variant
Dim Cnt As Long
Dim FileList() As String
Dim FileName As String
On Error GoTo OutOfHere
If Right(FolderPath, 1) <> "\" Then FolderPath = FolderPath & "\"
If FileType = "" Then
FileType = ".*"
Else
If Left(FileType, 1) <> "." Then FileType = "." & FileType
End If
If FileFilter = "" Then FileFilter = "*"
FileName = Dir(FolderPath & FileFilter & FileType)
Do While FileName <> ""
FileName = Dir()
ReDim Preserve FileList(Cnt)
FileList(Cnt) = FileName
Cnt = Cnt + 1
Loop
OutOfHere:
If Err = 0 Then CreateFileList = FileList
On Error GoTo 0
End Function
Sub ListFiles()
Dim I As Long
Dim MyFiles As Variant
Dim MyArray() As String
Dim N As Long
Dim Rng As Range
Dim RngEnd As Range
MyFiles = CreateFileList("M:/Archived PO Responses/Domestic", ".xls")
N = UBound(MyFiles)
ReDim MyArray(N, 0)
For I = 0 To N
MyArray(I, 0) = MyFiles(I)
Next I
Set Rng = Worksheets("Processed Orders").Range("A1")
Set Rng = Cells(Rows.Count, Rng.Column).End(xlUp).Offset(1, 0)
Set Rng = Rng.Resize(N + 1, 1)
Rng = MyArray
End Sub
Bookmarks