first of all you will add FSO References
Step for Add:- Tools-Reference-Microsoft Scripting Runtime
and try below code
Sub File_name()
Dim fso As FileSystemObject
Dim fl As File
Dim fldr As Folder
Dim wb As Workbook
Set wb = ThisWorkbook
Set fso = New FileSystemObject
Application.FileDialog(
Application.FileDialog(
Dim fldpath As String
fldpath = Application.FileDialog(
& "\"
Set fldr = fso.GetFolder(fldpath)
i = 2
For Each fl In fldr.Files
Sheet3.Cells(i, "D").Value = fl.Name
i = i + 1
Next fl
End Sub
No comments:
Post a Comment