KlausW
Active Member
- Joined
- Sep 9, 2020
- Messages
- 469
- Office Version
- 2016
- Platform
- Windows
Hi all
Someone who can help. I am using the VBA code to get a list (docx, PDF, JPG) of files in a folder. Where it is displayed in columns 22 and 23. But the it does not fetch anything.
Any help would be appreciated
Best regards Klaus W
Someone who can help. I am using the VBA code to get a list (docx, PDF, JPG) of files in a folder. Where it is displayed in columns 22 and 23. But the it does not fetch anything.
Any help would be appreciated
Best regards Klaus W
VBA Code:
Sub Hent_forslag()
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("D:\DNBR 2025\Hoffet\Menuforslag godkendt sendt\")
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 - 100 Then
WS.Cells(i + 2, 22) = oFolder.path
WS.Cells(i + 2, 23) = oFile.Name
' ws.Cells(i + 1, 3) = "RO"
'ws.Cells(i + 1, 4) = oFile.DateLastModified
'ws.Cells(i + 1, 5) = oFile.Size / 1024 ^ 2
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