The following code lists all files in a selected folder. Is there any way to list only files that contain specific text. In my case I want to only list files with both brackets. From the list below, output is Volume 1 (Section 1) and Volume 3 (S7). Text within brackets maybe of any length.
I would like to keep code in the same format.
Volume 1 (Section 1)
Volume 2 All
Volume 3 (S7)
Volume 4, Section 10
Volume 5 - Section 3
Sub File_Attributes()
Dim sFolder As FileDialog
Set sFolder = Application.FileDialog(msoFileDialogFolderPicker)
If sFolder.Show = -1 Then
File_Attributes_List_Files sFolder.SelectedItems(1), True
End If
End Sub
Sub File_Attributes_List_Files(ByVal SourceFolderName As String, ByVal IncludeSubfolders As Boolean)
Dim FSO As Object
Dim SourceFolder As Object
Dim SubFolder As Object
Dim FileItem As Object
Dim r As Long
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = FSO.GetFolder(SourceFolderName)
r = ActiveCell.Row
For Each FileItem In SourceFolder.Files
Rows(r).Insert
Cells(r, 3).Formula = FileItem.Name
r = r + 1
x = SourceFolder.Path
Next FileItem
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
File_Attributes_List_Files SubFolder.Path, True
Next SubFolder
End If
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
ActiveWorkbook.Saved = True
End Sub
Bookmarks