In this article, you will learn how to print all Workbooks in a folder using VBA in Excel. Let’s see them below!! Get the official version of MS Excel from the following link: https://www.microsoft.com/en-in/microsoft-365/excel
Example
- Firstly, you have some Excel files within a folder which we want to print.
- In the Excel Worksheet, you have to go to the Developer Tab.
- Then, you need to ** ** select the Visual Basic option under the Code section.
- Now, you have to copy and paste the code given below.
Option Explicit
Sub PrintAllWorkbooksInFolder(TargetFolder As String, FileFilter As String)
'Declaring variable
Dim FileName As String
'Disabling screen updates
Application.ScreenUpdating = False
'Adding path separator in the end of target folder name
If Right(TargetFolder, 1) <> "\" Then
TargetFolder = TargetFolder & "\"
End If
'Assigning default path to file filter
If FileFilter = "" Then FileFilter = "*.xls"
'Get the file name of first file in the folder
FileName = Dir(TargetFolder & FileFilter)
While Len(FileName) > 0
If FileName <> ThisWorkbook.Name Then
'Open workbook
Workbooks.Open TargetFolder & FileName
'Prints all sheets in the workbook
ActiveWorkbook.PrintOut
'Close the workbook without saving any changes
ActiveWorkbook.Close False
End If
'Get file name of next file in the folder
FileName = Dir
Wend
End Sub
Sub CallingProcedure()
'Declaring variables
Dim FolderPath, FileName As String
'Getting values from textbox on sheet1
FolderPath = Sheet1.TextBox1.Value
FileName = Sheet1.TextBox2.Value
'Calling PrintAllWorkbooksInFolder procedure
PrintAllWorkbooksInFolder FolderPath, FileName
End Sub
- You need to save the code by selecting it and then close the window.
- Again, you have to go to the Excel Spreadsheet , and click on the Developer Tab.
- You need to choose the Macros option in the Code section.
- Then, you have to make sure that your macro name is selected and click the *Run * button.
- Now, you need to specify folder path and specify file name in the Excel.
- Finally, you will print all Workbooks in a folder using VBA in Excel.
End of Era
We hope that this tutorial gives you guidelines on how to print all Workbooks in a folder using VBA in Excel. Please leave a comment in case of any queries, and don’t forget to mention your valuable suggestions as well. Thank you so much for Visiting Our Site!! Continue learning on Geek Excel!! *Read more on Excel Formulas *!!
Read Next:
- How to use the XNPV function in Excel office 365?
- Excel Formulas to Highlight the Cells that End with Given Value!!
- Shortcut for “Select to End of Cell” in the Worksheet!!
- Excel Shortcuts: Delete to the End of Line in the Spreadsheet!!
- Excel Formulas for Counting Cells that End with certain character or text!!






Latest comments (0)