List of files in a folder. VBA-code not running?

KlausW

Active Member
Joined
Sep 9, 2020
Messages
469
Office Version
  1. 2016
Platform
  1. 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

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
 
I find the solution my self, I'm just changing the number in this line. From 100 to 400

KW

VBA Code:
If oFile.DateLastModified > Now - 400 Then
 
Upvote 0
Solution

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top