MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.
Sub TestListFilesInFolder() Workbooks.Add ' create a new workbook for the file list ' add headers With Range("A1") .Formula = "Folder contents:" .Font.Bold = True .Font.Size = 12 End With Range("A3").Formula = "File Name:" Range("D3").Formula = "Date Created:" Range("A3:H3").Font.Bold = True ListFilesInFolder "X:\Co50Reports\", True ' list all files included subfolders End Sub Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As Boolean) ' lists information about the files in SourceFolder ' example: ListFilesInFolder "C:\FolderName\", True Dim FSO As Scripting.FileSystemObject Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder Dim FileItem As Scripting.File Dim r As Long Set FSO = New Scripting.FileSystemObject Set SourceFolder = FSO.GetFolder(SourceFolderName) r = Range("A65536").End(xlUp).Row + 1 For Each FileItem In SourceFolder.Files ' display file properties Cells(r, 1).Formula = FileItem.Path & FileItem.Name Cells(r, 2).Formula = FileItem.DateCreated ' use file methods (not proper in this example) ' FileItem.Copy "C:\FolderName\Filename.txt", True ' FileItem.Move "C:\FolderName\Filename.txt" ' FileItem.Delete True r = r + 1 ' next row number Next FileItem If IncludeSubfolders Then For Each SubFolder In SourceFolder.SubFolders ListFilesInFolder SubFolder.Path, True Next SubFolder End If Columns("A:H").AutoFit Set FileItem = Nothing Set SourceFolder = Nothing Set FSO = Nothing ActiveWorkbook.Saved = True End Sub
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
|any combination of this numbers||9||31|
|Turning off query prompts on runtime version of Access 2016||5||18|
|How to add extra IF statement to a loop in MS Access VBA||3||22|
|Need to query data and populate the sheet with the select||6||9|