Hi, I made a user form consisting of a Command Button "Browse". When a user clicks on it, a dialog box appears to search for a folder. Now when a folder is selected, I want that the Name of all the Files inside that selected Folder should be copied in my excel sheet.
I tried coding for the same, here's my try:
I tried running this code, but it shows error in the line
Can anyone help me code this?
I tried coding for the same, here's my try:
Code:
Private Sub CommandButton1_Click()Dim fName As Object
Dim fObjct As Object
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then
fName = .SelectedItems(1)
End If
End With
If fName <> "" Then
For Each fObjct In fName
Sheets("Sheet5").Cells(i + 1, 5) = fObjct.Name
i = i + 1
Next fObjct
End If
End Sub
I tried running this code, but it shows error in the line
"Object Variable or With variable not set".fName = .SelectedItems(1)
Can anyone help me code this?