Dave,
I took the liberty to abbreviate your code a little and add a Directory
picker function and extension input box:
Public Sub CreateFileList()
Dim aDir As Variant
Dim i As Integer
Dim oDoc As Document
Dim PathToUse As String
Dim pExt As String
PathToUse$ = GetPathToUse
If PathToUse = "No selection" Or PathToUse = "Error" Then Exit Sub
pExt = InputBox("Enter file extension or '*' for all file types.", _
"Extension", "*")
Set oDoc = Documents.Add
aDir = fDirList(PathToUse, "." & pExt)
For i = 0 To UBound(aDir)
oDoc.Range.InsertAfter aDir(i) & vbCrLf
Next i
End Sub
Public Function fDirList(sPath As String, sExt As String) As Variant
Dim MyFile As String
Dim Counter As Long
'Create a dynamic array variable declare a liberal initial size
Dim DirListArray() As String
ReDim DirListArray(0) As String
Counter = 0
'Loop through all the files in the directory by using Dir$ function
MyFile = Dir$(sPath & "*" & sExt)
Do While MyFile <> ""
DirListArray(Counter) = MyFile
MyFile = Dir$
Counter = Counter + 1
ReDim Preserve DirListArray(Counter)
Loop
fDirList = DirListArray
End Function
Private Function GetPathToUse() As Variant
On Error GoTo Handler
'Get the folder containing the files. Note - The "Copy Dialog" is used
to
'to display the "open" option
With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
GetPathToUse = .Directory
Else
GetPathToUse = "No selection"
Exit Function
End If
End With
If Left(GetPathToUse, 1) = Chr(34) Then
GetPathToUse = Mid(GetPathToUse, 2, Len(GetPathToUse) - 2)
End If
Exit Function
Handler:
GetPathToUse = "Error"
Err.Clear
End Function