Hi guys,
i got a VBA code working for extracting data about files in a specific folder. i would like to know if its possible for me to get data from multiple folders? i would like to add the data from these to my list below. The list below contains data from the folder in the VBA code you can see below.
<colgroup><col><col></colgroup><tbody>
</tbody>
i got a VBA code working for extracting data about files in a specific folder. i would like to know if its possible for me to get data from multiple folders? i would like to add the data from these to my list below. The list below contains data from the folder in the VBA code you can see below.
Filename | Date modified |
CPM_422.pptx | 2019-09-09 10:35 |
CPM_517.pptx | 2019-10-11 09:00 |
CPM_522.pptx | 2019-06-12 13:29 |
CPM_533.pptx | 2019-08-15 12:31 |
CPM_538.pptx | 2019-08-29 10:07 |
<colgroup><col><col></colgroup><tbody>
</tbody>
Code:
Sub GetFilesDetails()
' enable "microsoft scripting runtime" under tools -> references
' This macro will extract the list of the filenames from a folder as follows
' in column A= Files names
' in column B= Date Created
' in column C= Date Last Accessed
' in column D= Date Last Modified
Dim objFSO As Scripting.FileSystemObject
Dim myFolder As Scripting.Folder
Dim myFile As Scripting.File
Dim R As Long
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set myFolder = objFSO.GetFolder("C:\Users\vmgh\1. Portfolio\One pagers")
Application.ScreenUpdating = False
''******************************************************************************
' these 2 code lines will clear the old data in Sheet1 from columns A:D
' Row 1 is for the appropriate headers only
ThisWorkbook.Sheets("Sheet1").Range(Cells(2, 1), Cells(Rows.Count, 2)).ClearContents
R = 2
''********************************************************************
' Here we get the files details from folder and place them in the appropriate cells
For Each myFile In myFolder.Files
ThisWorkbook.Sheets("Sheet1").Cells(R, 1).Value = myFile.Name
ThisWorkbook.Sheets("Sheet1").Cells(R, 2).Value = myFile.DateLastModified
R = R + 1
Next myFile
'''************Resizing the columns width****************
ThisWorkbook.Sheets("Sheet1").Columns("A:B").EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub