I am trying to do the following:
find folder based on the path given by a cell value
determine whether it's subfolders are empty
if the subfolders are all empty - put "subfolders empty" in a cell
if there are some files within any of the subfolders
put "contains files in a cell"
My code runs but it is skipping over the subfolders sub procedure.
Sub search_subfolders()
Application.ScreenUpdating = False
On Error Resume Next
With Workbooks("Folder_creator.xlsm").Sheets("Sheet1")
Dim Rng As Range
Dim Pth As String
Dim Model As String
Dim x As String
Set Rng = .Range("a2:a527")
Pth = .Range("b2").Value
For r = 2 To 527
Model = .Cells(r, 1).Text
ModelPth = Pth & Model & "\"
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubFolders FSO.ModelPth
.Cells(r, 4).Value = x
Next r
End With
Application.ScreenUpdating = True
End Sub
Sub ShowSubFolders(ModelPth)
For Each Subfolder In ModelPath.SubFolders
If Subfolder.Size = 0 Then
x = "Subfolders empty"
Else
x = "Contains files"
End If
ShowSubFolders Subfolder
Next
End Sub
I think this is something to do with trying to pass variables to it without the correct syntax.
Ok, there are a number of problems with your code. Please see the code below for something that should work. I tried to explain changes with comments. Feel free to comment on this post if you need me to elaborate. Good luck, hope this helps.
Also, I wasn't sure if you wanted to check your ModelPth folder or subfolders in your ModelPth folder, so I made subroutines for both. I also took the liberty of implementing some small scale error handling.
'x needs to be declared here if it is to be accessed by multiple subroutines
Private x As String
Sub search_subfolders()
Application.ScreenUpdating = False
'Removed "On Error Resume next" .... this should only be used very sparingly
'Slightly better is to only use on a short section followed by "On Error Goto 0"
'or use "On Error Goto xyz" where "xyz" is a label
Dim sheet As Worksheet
'Perhaps you do want to refer to a workbook other than the one calling this macro
'but my guess is that this is intended to run within the workbook calling in
'in which case, it's much better to use "Activeworkbook" than to rely on a name that may change
'You may want to also reconsider your use of "Sheet1", you can use Sheets(1) which has it's own problems, or use "ActiveSheet",
'or just use "Range("B2")" which, is the same as ActiveWorkbook.ActiveSheet.Range("B2")
Set sheet = ActiveWorkbook.Sheets("Sheet1")
'If code is housed under a sheet module instead of in a standard module,
'your best option is to use "Set sheet = Me" and workbook shouldn't need to be specified.
'If you do ever want to specify calling workbook, you can use "ThisWorkbook"
Dim Rng As Range
Set Rng = sheet.Range("A2:A527")
Dim Pth As String
Pth = sheet.Range("b2").Value
Dim Model As String
'It's really best to avoid using "with" statements... just declare a variable and run with that
'In this case just make a sheet variable
For r = 2 To 527
Model = sheet.Cells(r, 1).Text
ModelPth = Pth & Model & "\"
'Are you sure ModelPth is in the correct syntax?
'That is, youmay want (Pth & "\" & Model & "\") instead.
CheckSubFolderContent ModelPth
sheet.Cells(r, 4).Value = x
CheckFolderContent ModelPth
sheet.Cells(r, 5).Value = x
Next r
End Sub
Sub CheckSubFolderContent(ModelPth)
'Checks for content in subfolders in a folder specified by path
x = "No Subfolders found"
'Error handling for Model = ""
If Right(ModelPth, 2) = "\\" Then
x = "N/A"
Exit Sub
End If
Dim FSO, Parent As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set Parent = FSO.GetFolder(ModelPth)
If Err > 0 Then
x = "Error! Parent folder does not exist."
Exit Sub
End If
For Each Subfolder In Parent.SubFolders
If Subfolder.Size = 0 Then
x = "Folder has subfolders without content"
Else
x = "Folder has subfolders with content"
End If
'Why this recursive line? "ShowSubFolders Subfolder"
'Recursive calls should be avoided and are rarely necesary.
Next
If Err > 0 Then x = "Error!"
On Error GoTo 0
End Sub
Sub CheckFolderContent(ModelPth)
'Checks for content in a folder specified by path
x = "No Subfolders found"
If Right(ModelPth, 2) = "\\" Then
x = "N/A"
Exit Sub
End If
Dim FSO, Folder As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set Folder = FSO.GetFolder(ModelPth)
If Err > 0 Then
x = "Error! Parent folder does not exist."
Exit Sub
End If
If Folder.Size = 0 Then
x = "Folder is empty"
Else
x = "Folder has content"
End If
If Err > 0 Then x = "Error!"
On Error GoTo 0
End Sub
Couple of things you are doing wrong.
1. You are trying to access sub-folders without making FSO(FileSystemObject) accessible in ShowSubFolders sub.
2. x is not global variable and yet you are trying to access it.
3. Less conditions in ShowSubFolders sub.
Here is the updated code.
Dim FSO As Object '<-- This one sets FSO global
Dim x As String '<-- This one sets x global
Sub search_subfolders()
Application.ScreenUpdating = False
On Error Resume Next
Workbooks("Folder_creator.xlsm").Sheets("Sheet1")
Dim Rng As Range
Dim Pth As String
Dim Model As String
Set Rng = .Range("a2:a527")
Pth = .Range("b2").Value
For r = 2 To 527
Model = .Cells(r, 1).Text
ModelPth = Pth & Model & "\"
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubFolders FSO.GetFolder(ModelPth)
.Cells(r, 4).Value = x
x = ""
Next r
End With
Application.ScreenUpdating = True
End Sub
Sub ShowSubFolders(Folder)
Dim SubFolder
If Folder.SubFolders.Count > 0 Then
For Each SubFolder In Folder.SubFolders
ShowSubFolders SubFolder
If SubFolder.Size = 0 Then
x = "Subfolders empty"
Else
x = "Contains files"
End If
Next
Else
x = "Subfolders empty"
End If
End Sub
Related
I would like the following code to run each time the workbook opens. I am getting a couple of errors that you can see in my comments. I'm pretty sure it is a very simple thing that I am missing and I have not been able to figure it out. Thank you for your time!
Public FSO As Scripting.FileSystemObject
Public SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
Public FileItem As Scripting.File
Public FolderName As Object
Private Sub Workbook_Open()
'I would like to run this every time the workbook opens. This is where I am getting my Argument Not Optional Error.
Call ListFilesInFolder(SourceFolder)
End Sub
Sub ListFilesInFolder(SourceFolder As Scripting.Folder, Subfolders As Boolean) 'Do I need everything in the parentheses?
Application.ScreenUpdating = False
MsgBox "SOP's Database will update automatically"
Dim r, LstR As Long
Dim SOPRng As Range
Set SOPRng = ActiveSheet.ListObjects("SOPDatabase").Range
ActiveSheet.ListObjects("SOPDatabase").Unlist
SOPRng.ClearFormats
UserName = Environ("UserName")
fPath = "Target File Path"
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(fPath)
r = 2
On Error Resume Next
For Each FileItem In SourceFolder.Files
Cells(r, 1) = r - 1
Cells(r, 2) = FileItem.Name
Cells(r, 3) = FileItem.Type
Cells(r, 4) = FileItem.DateLastModified
Cells(r, 6).Formula = "=HYPERLINK(""" & FileItem.Path & """,""" & "Click Here to Open" & """)"
r = r + 1
Next FileItem
I can get up to here to work just fine. Going into the subfolders below is not working. I am getting error.
If Subfolders Then
For Each SubFolder In SourceFolder.Subfolders
ListFilesInFolder SubFolder, True '"wrong number of arguments or invalid property assignment" and "ListFilesInFolder" is highlighted
Next SubFolder
End If
'The rest of the macro is working just fine.
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
LstR = ActiveSheet.Columns("$B").End(xlDown).Row
Set SOPRng = ActiveSheet.Range("$A$1:$G$" & LstR)
Set SOPDatabase = ActiveSheet.ListObjects.Add(xlSrcRange, SOPRng, , xlYes, , "TableStyleMedium2")
SOPDatabase.Name = "SOPDatabase"
With SOPDatabase.Range
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
With SOPDatabase.HeaderRowRange
.Font.Bold = True
.Font.Size = 14
.Font.Color = vbBlack
.WrapText = True
End With
Application.ScreenUpdating = True
End Sub
It may be my lack of knowledge of VBA and how to define variables. I am still trying to understand that part.
change
Call ListFilesInFolder(SourceFolder)
to
Call ListFilesInFolder(SourceFolder,True)
this should at least yield a different error from your current one
I don't think the code you posted will compile. You call Call ListFilesInFolder(SourceFolder), but the sub requires two arguments: SourceFolder and Subfolders. Did you perhaps add the Subfolders parameter to ListFilesInFolder(SourceFolder As Scripting.Folder, Subfolders As Boolean) AFTER you got the "wrong number of arguments" error in ListFilesInFolder SubFolder, True?
In other words, does this code currently compile and run up until ListFilesInFolder SubFolder, True?
I want to access a folder using VBA and loop through all Excel files in all subfolders. More specifically, I want to gather data from specific cells in each file and dump the data in my active workbook. Something i feel should be easy to write up but I've been unsuccessful so far. I've tried a few methods for looping through subfolders that I found online but they haven't helped.
Here's a visual idea of what I'd like to achieve:
Sub example()
'Find a way to enter file path
'Find a way to loop through subfolders
'Find a way to loop through excel files and refer to current file below
x = 2
Workbooks(Loop Test.xlsm).Worksheets("Sheet1").Cells(x,1) = 'current file in loop range A1
Workbooks(Loop Test.xlsm).Worksheets("Sheet1").Cells(x,2) = 'current file in loop range A2
' etc.
x = x + 1
' next file
End Sub
Writing a function to return the list of files will make testing easier.
Test
Sub TestGetFileList()
Dim f As Variant, fileList As Object
Set fileList = getFileList("C:\Level 1")
For Each f In fileList
Debug.Print f
Next
End Sub
getFileList:Function
Function getFileList(Path As String, Optional FileFilter As String = "*.xls?", Optional fso As Object, Optional list As Object) As Object
Dim BaseFolder As Object, f As Object
If fso Is Nothing Then
Set fso = CreateObject("Scripting.FileSystemObject")
Set list = CreateObject("System.Collections.ArrayList")
'Set list = CreateObject("Scripting.Dictionary")
End If
If Not Right(Path, 1) = "\" Then Path = Path & "\"
If Len(Dir(Path, vbDirectory)) = 0 Then
MsgBox Path & " not found"
Exit Function
End If
Set BaseFolder = fso.GetFolder(Path)
For Each f In BaseFolder.SubFolders
getFileList f.Path, FileFilter, fso, list
Next
For Each f In BaseFolder.files
If f.Path Like FileFilter Then list.Add f.Path
Next
Set getFileList = list
End Function
Think I've got it:
Sub Test2()
Dim wb As Workbook, ws As Worksheet
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("C:\Users\azrae\OneDrive\Desktop\To Be Transferred\Optimum\Test Folder\")
x = 2
For Each sfldr In fldr.SubFolders
For Each wbfile In sfldr.Files
If fso.getextensionname(wbfile.Name) = "xlsx" Then
Set wb = Workbooks.Open(wbfile.Path)
End If
Workbooks("Loop Test.xlsm").Worksheets("Sheet1").Cells(x, 1) = wb.Worksheets("Sheet1").Range("A1")
Workbooks("Loop Test.xlsm").Worksheets("Sheet1").Cells(x, 2) = wb.Worksheets("Sheet1").Range("A2")
Workbooks("Loop Test.xlsm").Worksheets("Sheet1").Cells(x, 3) = wb.Worksheets("Sheet1").Range("A3")
wb.Close
x = x + 1
Next wbfile
Next sfldr
End Sub
Let me know if you have a smoother method.
I have 27 txt files with the same format and columns, and I want to append all of these in a single excel sheet. I have checked some previous threads here, but I could only find the code below which helped me to import txt fiels into separate sheets. However, I also want to append these separate sheets into a sheet that I want to append all my data.
Sub Test()
'UpdatebyExtendoffice6/7/2016
Dim xWb As Workbook
Dim xToBook As Workbook
Dim xStrPath As String
Dim xFileDialog As FileDialog
Dim xFile As String
Dim xFiles As New Collection
Dim I As Long
Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
xFileDialog.AllowMultiSelect = False
xFileDialog.Title = "Select a folder [Vendor_data_25DEC]"
If xFileDialog.Show = -1 Then
xStrPath = xFileDialog.SelectedItems(1)
End If
If xStrPath = "" Then Exit Sub
If Right(xStrPath, 1) <> "\" Then xStrPath = xStrPath & "\"
xFile = Dir(xStrPath)
'xFile = Dir(xStrPath & "*.txt") 'this is the original version that you can amend according to file extension
If xFile = "" Then
MsgBox "No files found", vbInformation, "Vendor_data_25DEC"
Exit Sub
End If
Do While xFile <> ""
xFiles.Add xFile, xFile
xFile = Dir()
Loop
Set xToBook = ThisWorkbook
If xFiles.Count > 0 Then
For I = 1 To xFiles.Count
Set xWb = Workbooks.Open(xStrPath & xFiles.Item(I))
xWb.Worksheets(1).Copy after:=xToBook.Sheets(xToBook.Sheets.Count)
On Error Resume Next
ActiveSheet.Name = xWb.Name
On Error GoTo 0
xWb.Close False
Next
End If
End Sub
I am not sure how to do this with VBA in order to combine the data in separate sheets into a single sheet quickly. I know the consolidate feature of excel but it also includes lots of manual steps, so I seek for a faster and automated solution. Any help is much appreciated.
Thanks a lot in advance.
Sub Combiner()
Dim strTextFilePath$, strFolder$
Dim wksTarget As Worksheet
Dim wksSource As Worksheet
Dim x As Long
Set wksTarget = Sheets.Add()
strFolder = "c:\Temp\test\"
strTextFilePath = Dir(strFolder)
While Len(strTextFilePath) > 0
'// "x" variable is just a counter.
'// It's purpose is to track whether the iteration is first or not.
'// If iteration is first (x=1), then we include header (zero offset down),
'// otherwise - we make an offset (1 row offset down).
x = x + 1
Set wksSource = Workbooks.Open(strFolder & strTextFilePath).Sheets(1)
With wksTarget
wksSource.Range("A1").CurrentRegion.Offset(IIf(x = 1, 0, 1)).Copy _
.Cells(.Rows.Count, 1).End(xlUp).Offset(1)
End With
wksSource.Parent.Close False
strTextFilePath = Dir()
Wend
MsgBox "Well done!", vbInformation
End Sub
I have the following working codes.
Column B has image names, this pulls images in the selected folder that match the names in column B and inserts them into Column A (please note, first two rows are used for my header). I've noticed that the code errors if the header in B2 is missing, then the code errors out. I would like to fix this so it will only try to find images if there is a name in Range("B3:B1002").
Option Explicit
Private Sub Add_Images_Click()
Const EXIT_TEXT As String = ""
Const NO_PICTURE_FOUND As String = "No picture found"
Dim picName As String
Dim picFullName As String
Dim rowIndex As Long
Dim lastRow As Long
Dim selectedFolder As String
Dim data() As Variant
Dim wks As Worksheet
Dim Cell As Range
Dim pic As Picture
On Error GoTo ErrorHandler
selectedFolder = GetFolder
If Len(selectedFolder) = 0 Then GoTo ExitRoutine
Application.ScreenUpdating = False
Set wks = ActiveSheet
lastRow = wks.Cells(2, "B").End(xlDown).Row
data = wks.Range(wks.Cells(1, "B"), wks.Cells(lastRow, "B")).Value2
For rowIndex = 3 To UBound(data, 1)
If StrComp(data(rowIndex, 1), EXIT_TEXT, vbTextCompare) = 0 Then GoTo ExitRoutine
picName = data(rowIndex, 1)
picFullName = selectedFolder & picName
If Len(Dir(picFullName)) > 0 Then
Set Cell = wks.Cells(rowIndex, "A")
Set pic = wks.Pictures.Insert(picFullName)
With pic
.ShapeRange.LockAspectRatio = msoFalse
.Height = Cell.Height
.Width = Cell.Width
.Top = Cell.Top
.Left = Cell.Left
.Placement = xlMoveAndSize
End With
Else
wks.Cells(rowIndex, "A").Value = NO_PICTURE_FOUND
End If
Next rowIndex
ExitRoutine:
Set wks = Nothing
Set pic = Nothing
Application.ScreenUpdating = True
Exit Sub
ErrorHandler:
MsgBox Prompt:="Unable to find photo", _
Title:="An error occured", _
Buttons:=vbExclamation
Resume ExitRoutine
End Sub
This is the Function that has the user select the folder that contains the images when the above sub is ran. I would like to modify this if possible to also work with an URL like an FTP site. So if the images are in a folder on the users pc, it will run like below, but if the images are located in a FTP location, it will still be able to pull the images.
Private Function GetFolder() As String
Dim selectedFolder As String
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Select the folder containing the Image/PDF files."
.Show
If .SelectedItems.Count > 0 Then
selectedFolder = .SelectedItems(1)
If Right$(selectedFolder, 1) <> Application.PathSeparator Then _
selectedFolder = selectedFolder & Application.PathSeparator
End If
End With
GetFolder = selectedFolder
End Function
This Sub is meant to remove all images from column A. The problem is that this works too well. It is fine when used with a normal button, but when I try using a CommandButton to have my buttons on a user form, this Sub removes the CommandButton. It also removes all comments from the sheet. I would like to either limit this to only remove images, or to quarantine the code to only look at Range("A3:A1002").
Private Sub Remove_Images_Click()
'Remove Images
Dim wks As Worksheet
Dim shp As Shape
Dim picArray() As String
Dim index As Integer
On Error GoTo ErrorHandler
Columns(1).Replace What:="No Picture Found", Replacement:=vbNullString, LookAt:=xlPart
Set wks = ActiveSheet
index = 1
For Each shp In wks.Shapes
If shp.Type <> msoFormControl Then
ReDim Preserve picArray(1 To index)
picArray(index) = shp.Name
index = index + 1
End If
Next shp
wks.Shapes.Range(picArray).Delete
ExitRoutine:
Set wks = Nothing
Set shp = Nothing
Erase picArray
Exit Sub
ErrorHandler:
MsgBox Prompt:="Unable to find photo", _
Title:="An error occured", _
Buttons:=vbExclamation
Resume ExitRoutine
End Sub
I see three main questions, probably better to separate these into different questions but I'll give it a shot.
Ignore row 2 in the first code block.
Change 1 to 3 on this line: data = wks.Range(wks.Cells(3, "B"), wks.Cells(lastRow, "B")).Value2 This sets your data range starting at row 3 and ignores your two header rows.
FTP link
This is better suited for a separate question. Start by creating a new function that handles FTP links. Then identify which path is in the cell, i.e. does it start with http, c://, etc... Then call appropriate function and have it return the image to the main program.
Check if shape is in column A.
Use the TopLeftCell attribute and see if it intersects column A
For Each shp In wks.Shapes
If Not Intersect(shp.TopLeftCell, Columns(1)) Is Nothing Then '<-- New Line checks if in col A
If shp.Type <> msoFormControl Then
....
first-time poster but long-time fan for finding VBA and SQL solutions on this site. I have a VBA subroutine that is designed to find all PDF files within a directory that the user designates. The program does recursions through all subfolders and generates a spreadsheet as follows:
Column A: complete file path ("C:\Users\Records\NumberOne.pdf")
Column B: folder path containing the file ("C:\Users\Records\")
Column C: the file name itself ("NumberOne.pdf")
Up to this point, the program (code below) works flawlessly. I've used it to search a directory with over 50,000 PDF files, and it successfully generates the spreadsheet every time (total elapsed time for the program is usually 5-10 minutes in large directories).
The problem is that I want to add Column D to capture the date that the PDF file was created. I have Googled this and labored over it for hours, trying techniques like FSO.DateCreated and so forth, and nothing has worked. If FSO.DateCreated is what I need, I'm not sure where to insert it in my subroutine to make it work. Usually I get an error that the object does not support that property or method. Does anybody happen to know where I can insert the proper code for my program to find the date each PDF was created and drop it into Column D on my output spreadsheet?
Sub GetFiles()
'-- RUNS AN UNLIMITED RECURSION SEARCH THROUGH A TARGETED FOLDER AND FINDS ALL PDF FILES WITHIN
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim j As Long
Dim ThisEntry As String
Dim strDir As String
Dim FSO As Object
Dim strFolder As String
Dim strName As String
Dim DateCreated As Date '--(Possibly String?)
Dim strArr(1 To 1048576, 1 To 1) As String, i As Long
Dim fldr As FileDialog
'-- OPEN DIALOG BOX TO SELECT DIRECTORY THE USER WISHES TO SEARCH
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select the directory you wish to search"
.AllowMultiSelect = False
If .Show <> -1 Then
Exit Sub
Set fldr = Nothing
Else
strDir = .SelectedItems(1) & "\"
End If
End With
'-- LOOK FOR RECORDS WORKSHEET; IF IT DOES NOT EXIST, CREATE IT; IF IT DOES EXIST, CLEAR CONTENTS
If Not (wsExists("records")) Then
Worksheets.Add
With ActiveSheet
.Name = "records"
End With
Set ws = ActiveSheet
Else
Sheets("records").Activate
Range("A1:IV1").EntireColumn.Delete
Set ws = ActiveSheet
End If
'-- SET SEARCH PARAMETERS
Let strName = Dir$(strDir & "\" & "*.pdf")
Do While strName <> vbNullString
Let i = i + 1
Let strArr(i, 1) = strDir & strName
Let strName = Dir$()
Loop
'-- UNLIMITED RECURSIONS THROUGH SUBFOLDERS
Set FSO = CreateObject("Scripting.FileSystemObject")
Call recurseSubFolders(FSO.GetFolder(strDir), strArr(), i)
Set FSO = Nothing
'-- CREATE COLUMN HEADERS ON OUTPUT WORKSHEET
With ws
Range("A1").Value = "AbsolutePath"
Range("B1").Value = "FolderPath"
Range("C1").Value = "FileName"
Range("D1").Value = "DateCreated"
End With
If i > 0 Then
ws.Range("A2").Resize(i).Value = strArr
End If
lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lr
ThisEntry = Cells(i, 1)
'-- EXTRACT FOLDER PATH AND FILE NAME FROM STRING
For j = Len(ThisEntry) To 1 Step -1
If Mid(ThisEntry, j, 1) = Application.PathSeparator Then
Cells(i, 2) = Left(ThisEntry, j)
Cells(i, 3) = Mid(ThisEntry, j + 1)
Exit For
End If
Next j
Next i
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
----------
Private Sub recurseSubFolders(ByRef Folder As Object, _
ByRef strArr() As String, _
ByRef i As Long)
Dim SubFolder As Object
Dim strName As String
For Each SubFolder In Folder.SubFolders
Let strName = Dir$(SubFolder.Path & "\" & "*.pdf")
Do While strName <> vbNullString
Let i = i + 1
Let strArr(i, 1) = SubFolder.Path & "\" & strName
Let strName = Dir$()
Loop
Call recurseSubFolders(SubFolder, strArr(), i)
Next
End Sub
You need to get the file with GetFile before you can access the DateCreated.
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(myFileName)
str = f.DateCreated
MsgBox (str)
Your code is fine (beside some issues with indentation). I just added the instruction to get the creation date from the file system, as you can see below:
Set FSO = CreateObject("Scripting.FileSystemObject")
For i = 1 To lr
ThisEntry = Cells(i, 1)
'-- EXTRACT FOLDER PATH AND FILE NAME FROM STRING
For j = Len(ThisEntry) To 1 Step -1
If Mid(ThisEntry, j, 1) = Application.PathSeparator Then
Cells(i, 2) = Left(ThisEntry, j)
Cells(i, 3) = Mid(ThisEntry, j + 1)
Cells(i, 4) = FSO.GetFile(ThisEntry).DateCreated
Exit For
End If
Next j
Next i
I don't know why you weren't able to use the FSO object, but I believe it can be because few lines below you set it to nothing, so I instantiated it again before the first For cycle:
Set FSO = CreateObject("Scripting.FileSystemObject")
Hope this helps,
The Macro Guru
FileSystem.FileDateTime(inputfilepath) returns a variant or date of when the file was last created or modified.