
VBA Dir in Excel — Loop Through Files in a Folder, and the Stateful Iterator That Bites You
Dir looks like a function but behaves like an iterator with hidden memory — Dir(path) returns the first matching file name, then Dir() with no arguments returns the next, and an empty string when the folder is exhausted. The one rule that saves you is never call Dir again in the middle of a Dir loop, because a second Dir starts a new search and resets the first — the number-one cause of skipped files and infinite loops. Learn how to loop every .xlsx in a folder, why Dir returns only the name and not the path, why it cannot recurse into subfolders, and when to collect the names into an array before you touch the files.



































































![Excel Sum of Time Over 24 Hours — Why Your Total Resets (and the [h]:mm Fix)](/_next/image?url=https%3A%2F%2Fexcelmasterstore.blob.core.windows.net%2Fexcelmaster%2Fcms%2Fblog-assets%2Fexcel-sum-time-over-24-hours%2Fhero.png&w=1200&q=75)







































































































![How to Convert .xlsb to .xlsx — 5 Free Methods (Excel, Online, Python, VBA) [2026]](/_next/image?url=https%3A%2F%2Fexcelmasterstore.blob.core.windows.net%2Fexcelmaster%2Fcms%2Fcovers%2Fv2-launch-agent-excel.png&w=1200&q=75)





















