Automate PDF page counts across your file list with ease.

If you’re looking to automate the counting of pages in PDF files listed in a folder using Power Query, you’re in the right place.

3 min readMicrosoft Excel | Help & Support with your Formula, Macro, and VBA problems | A Reddit Community

The request here is straightforward, and that is exactly why it deserves attention. A user wants to pull page counts from a folder full of PDFs, update it automatically, and do it all without VBA. No macros. No scripts that might scare off a third party. Just a clean, repeatable workflow built on tools that already ship with Excel. This is the kind of problem that separates a spreadsheet from a spreadsheet tool, and the fact that it can be solved with Power Query should be more widely known.

For anyone who has stared at a file list and wondered how to enrich it without breaking the workbook, the answer is hiding in plain sight. Power Query can already list every file in a folder. The missing piece is extracting the page count from each PDF, and that is where the community steps in with a genuinely clever approach. By reading the PDF as a binary and parsing the `/Type /Page` markers from the raw content, you can derive a page count without ever opening the file. It is not a built-in function, but it is a reliable, transparent method that updates on refresh and leaves no trace of VBA behind.

What this means for you is practical and immediate. You can build a folder query that lists every PDF, add a custom column that pulls the binary content, and then calculate page counts using a simple formula that counts the occurrences of a specific pattern. It is fast enough for a few files and scales fine for hundreds. More importantly, the result is a table that refreshes with a click, so when you drop a new PDF into the folder or remove an old one, your page count column stays in sync. No manual entry, no hidden dependencies, no security warnings for the person who receives the file.

This is not about being clever for the sake of it. It is about giving you a workflow that is shareable, auditable, and free of the fragility that comes with macros. The user who asked this question is not looking for a workaround; they are looking for a standard. And the answer is that Power Query, combined with a bit of parsing logic, delivers exactly that. If you have been avoiding this task because you assumed it required VBA, the assumption is the only thing standing between you and a fully automated solution. Build the query once, refresh it forever, and send the file out with confidence.

From Microsoft Excel | Help & Support with your Formula, Macro, and VBA problems | A Reddit Community

I'm frequently using power query for listing all the files in a folder.

Now when I list PDF files, it looks something like this:

Read the original at Microsoft Excel | Help & Support with your Formula, Macro, and VBA problems | A Reddit Community