Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50070

Grab Filenames of Files within Subfolders

$
0
0
Hello,

I know there are various internet threads regarding this subject but I'm looking for something to add to my code specifically and can't seem to make it work. Here is my code:

Formula:
Sub GetFilenames()
Dim UserCell As Range
Dim FilePath As String
Dim Filenames As String

Set UserCell = ActiveSheet.Range(frmGetFilename.txtboxColumn.Value & frmGetFilename.txtboxRow.Value)
FilePath = frmGetFilename.lblFilePath.Caption
Filenames = Dir(FilePath)

UserCell.Select
Do While Len(Filenames) > 0
ActiveCell.Formula = FilePath & Filenames
ActiveCell.Offset(1).Select
Filenames = Dir()
Loop
End Sub


The frmGetFilename.lblFilePath.Caption is generated on the userform using msoFileDialogFolderPicker. Anyway, I'm hoping there is a way to get the code to include filenames within subdirectories of that path.

Thanks.

Viewing all articles
Browse latest Browse all 50070

Trending Articles