An Excel Macro to Print All Workbooks in a Directory

By Michael Alexander

If you need to print from multiple Excel workbooks in a directory, you can use the macro presented here to print them all at once.

How the macro works

In this macro, you use the Dir function to return a string that represents the name of the file that matches what you pass to it.

You use the Dir function to enumerate through all .xlsx files in a given directory, capturing each file’s name. Then you open each file, print it, and then close it.

Sub Macro1()
'Step 1:Declare your variables
Dim MyFiles As String
'Step 2: Specify a target directory
MyFiles = Dir("C:Temp*.xlsx")
Do While MyFiles <> "
'Step 3: Open workbooks one by one
Workbooks.Open "C:Temp" & MyFiles