CaptnAbraham
New Member
- Joined
- Feb 10, 2022
- Messages
- 14
- Office Version
- 2019
- Platform
- Windows
Good day dear Excelists...
I have a working code which gets me all the filenames from a given folder (with about 200+ files), looking like this:
-----------------------------------------------------------
Private Sub CommandButton2_Click()
Dim xRow As Long
Dim xDirect$, xFname$, InitialFoldr$
InitialFoldr$ = "C:\Users\Name\Downloads\Folder\"
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a folder to list Files from"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Do While xFname$ <> ""
ActiveCell.Offset(xRow) = xFname$
xRow = xRow + 1
xFname$ = Dir
Loop
End If
End With
End Sub
-----------------------------------------------------------
The question is... Is there a way to also get the sheet names from within those files? Would that be a new code or is there a way to just attach that parameter here on top?
Normally there should be only one sheet per file but there might be a case where there is two (external files, who knows what silly things other people are up to). Each of the sheet names in these 200+ files are named differently.
Any help or pointers to a solution is much appreciated.
Thanks.
I have a working code which gets me all the filenames from a given folder (with about 200+ files), looking like this:
-----------------------------------------------------------
Private Sub CommandButton2_Click()
Dim xRow As Long
Dim xDirect$, xFname$, InitialFoldr$
InitialFoldr$ = "C:\Users\Name\Downloads\Folder\"
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a folder to list Files from"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Do While xFname$ <> ""
ActiveCell.Offset(xRow) = xFname$
xRow = xRow + 1
xFname$ = Dir
Loop
End If
End With
End Sub
-----------------------------------------------------------
The question is... Is there a way to also get the sheet names from within those files? Would that be a new code or is there a way to just attach that parameter here on top?
Normally there should be only one sheet per file but there might be a case where there is two (external files, who knows what silly things other people are up to). Each of the sheet names in these 200+ files are named differently.
Any help or pointers to a solution is much appreciated.
Thanks.