Macro to extract list of PDF Files in a date range

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,563
Office Version
  1. 2021
Platform
  1. Windows
I need to extract a list of all PDF files on my C:\drive that are modified between 24/12/2022 to 05/01/2023 (date format dd/mm/yyyy)

I would like a macro to extract a list of pdf files in this date range and also show which directory these are in


Your assistance is most appreciated
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You could do this with Power Query: Get Data -> From File -> From Folder. VBA isn't required.
And once you've filtered the initial query to get only PDF files, you can load the list to a table:
WTF.xlsx
ABCDE
1NameDate accessedDate modifiedDate createdSize
220180520.pdf02/20/2023 11:1706/12/2021 14:2706/12/2021 16:13128,066
320180527.pdf02/20/2023 11:1706/12/2021 14:3006/12/2021 16:13128,057
420180610.pdf02/20/2023 11:1706/12/2021 14:3206/12/2021 16:13127,523
520210115.pdf02/20/2023 11:1706/12/2021 15:0306/12/2021 16:13238,049
620210201.pdf02/20/2023 11:1706/12/2021 15:1806/12/2021 16:13328,149
720210217.pdf02/20/2023 11:1706/12/2021 15:2406/12/2021 16:13240,471
820210304.pdf02/20/2023 11:1706/12/2021 15:2906/12/2021 16:13258,566
920210322.pdf02/20/2023 11:1706/12/2021 15:3706/12/2021 16:13304,006
1020210407.pdf02/20/2023 11:1706/12/2021 15:4406/12/2021 16:13293,961
1120210425.pdf02/20/2023 11:1706/12/2021 15:4806/12/2021 16:13268,091
1220210511.pdf02/20/2023 11:1706/12/2021 15:5506/12/2021 16:13288,890
1320211229.pdf02/20/2023 11:1706/12/2021 16:0106/12/2021 16:13253,908
Sheet1
That uses this code which was generated entirely through the UI. I renamed Steps removing spaces so the code is clearer:
Power Query:
let
    Source = Folder.Files("C:\Documents\Receipts"),
    LowercasedText = Table.TransformColumns(Source,{{"Extension", Text.Lower, type text}}), // Insures all Extensions are Lower Case
    FilteredRows = Table.SelectRows(LowercasedText, each [Extension] = ".pdf"), // Removes all except ".pdf" Extensions
    RemovedColumns = Table.RemoveColumns(FilteredRows,{"Content" /* Actual File */, "Extension", "Folder Path"}),
    ExpandedSizeAttributes = Table.ExpandRecordColumn(RemovedColumns, "Attributes", {"Size"}, {"Size"}),
    ChangedType = Table.TransformColumnTypes(ExpandedSizeAttributes,{{"Size", Int64.Type}}),
    SortedRows = Table.Sort(ChangedType,{{"Name", Order.Ascending}})
in
    SortedRows
Text after "//" or between "/*" and "*/" are comments. The File Size was Extracted in the ExpandedSizeAttributes line. There's a ton of Attributes there, but typically only Size is useful!
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,685
Members
449,117
Latest member
Aaagu

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