I found the code below on an earlier post from 2002, but it did not give me the full path, including subfolders and file name. It just gave me the files in that particular folder and did not include the subfolders, etc. How do you change it so that I get the full path? I want to use it for an inventory and as a hyperlink to the file in other documents. I'm pretty new to VBA, so I appreciate your help.
VBA:
Sub ListFiles2()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
Dim fileList() As String<o></o>
Dim fName As String<o></o>
Dim fPath As String<o></o>
Dim i As Integer<o></o>
Dim startrow As Integer<o></o>
Dim ws As Worksheet<o></o>
Dim filetype As String<o></o>
<o> </o>
'=======================================================<o></o>
fPath = "C:\Temp\"<o></o>
filetype = "*"<o></o>
Set ws = Worksheets("Sheet2")<o></o>
startrow = 2 'starting row for the data<o></o>
'========================================================<o></o>
<o> </o>
fName = Dir(fPath & "*." & filetype)<o></o>
While fName <> ""<o></o>
i = i + 1<o></o>
ReDim Preserve fileList(1 To i)<o></o>
fileList(i) = fName<o></o>
fName = Dir()<o></o>
Wend<o></o>
If i = 0 Then<o></o>
MsgBox "No files found"<o></o>
Exit Sub<o></o>
End If<o></o>
<o></o>
For i = 1 To UBound(fileList)<o></o>
ws.Range("A" & i + startrow).Value = fileList(i)<o></o>
Next<o></o>
Columns(1).AutoFit<o></o>
<o> </o>
End Sub<o></o>
VBA:
Sub ListFiles2()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
Dim fileList() As String<o></o>
Dim fName As String<o></o>
Dim fPath As String<o></o>
Dim i As Integer<o></o>
Dim startrow As Integer<o></o>
Dim ws As Worksheet<o></o>
Dim filetype As String<o></o>
<o> </o>
'=======================================================<o></o>
fPath = "C:\Temp\"<o></o>
filetype = "*"<o></o>
Set ws = Worksheets("Sheet2")<o></o>
startrow = 2 'starting row for the data<o></o>
'========================================================<o></o>
<o> </o>
fName = Dir(fPath & "*." & filetype)<o></o>
While fName <> ""<o></o>
i = i + 1<o></o>
ReDim Preserve fileList(1 To i)<o></o>
fileList(i) = fName<o></o>
fName = Dir()<o></o>
Wend<o></o>
If i = 0 Then<o></o>
MsgBox "No files found"<o></o>
Exit Sub<o></o>
End If<o></o>
<o></o>
For i = 1 To UBound(fileList)<o></o>
ws.Range("A" & i + startrow).Value = fileList(i)<o></o>
Next<o></o>
Columns(1).AutoFit<o></o>
<o> </o>
End Sub<o></o>