Hi
how can i modify the below code to have dialog box to select folder instead of folder path in the code so user can select the folder when prompt.
thank you,
how can i modify the below code to have dialog box to select folder instead of folder path in the code so user can select the folder when prompt.
VBA Code:
Sub ListFiles2()
Dim fileList() As String
Dim fName As String
Dim fPath As String
Dim i As Integer
Dim startrow As Integer
Dim ws As Worksheet
Dim filetype As String
Dim sFolder As String
'=======================================================
[B][COLOR=rgb(184, 49, 47)]fPath = "C:\Weekly AP\"[/COLOR][/B]
filetype = "*"
Set ws = Worksheets("LIST_FILE NAMES")
startrow = 2 'starting row for the data
'========================================================
fName = Dir(fPath & "*." & filetype)
While fName <> ""
i = i + 1
ReDim Preserve fileList(1 To i)
fileList(i) = fName
fName = Dir()
Wend
If i = 0 Then
MsgBox "No files found"
Exit Sub
End If
For i = 1 To UBound(fileList)
ws.Range("A" & i + startrow).Value = fileList(i)
Next
Columns(1).AutoFit
End Sub
thank you,