I'm trying to get this bit of code to give me file names based on a cells directory. when i put in the folders directory it works just fine, though when i try and pull from the cell it doesnt. ("'Analysis'!D7") is the cell im trying to reference for what directory to look in.
VBA Code:
Sub getfiles()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object, sf
Dim i As Integer, colFolders As New Collection, ws As Worksheet
Set ws = ActiveSheet
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.getfolder("'Analysis'!D7")
colFolders.Add oFolder 'start with this folder
Do While colFolders.Count > 0 'process all folders
Set oFolder = colFolders(1) 'get a folder to process
colFolders.Remove 1 'remove item at index 1
For Each oFile In oFolder.Files
If oFile.DateLastModified > Now - 1 Then
ws.Cells(i + 20, 1) = oFolder.Path
ws.Cells(i + 20, 2) = oFile.Name
ws.Cells(i + 20, 3) = "RO"
ws.Cells(i + 20, 4) = oFile.DateLastModified
i = i + 1
End If
Next oFile
'add any subfolders to the collection for processing
For Each sf In oFolder.subfolders
colFolders.Add sf 'add to collection for processing
Next sf
Loop
End Sub