How To Print all workbooks in a folder using VBA in Excel?
Tags: toprintallworkbooksi, vbamacros
Published: 2021-09-30 08:09:12

---
title: How To Print all workbooks in a folder using VBA in Excel?
published: true
date: 2021-09-29 05:53:31 UTC
tags: ToPrintAllWorkbooksI,VBAMacros
canonical_url: https://geekexcel.com/how-to-print-all-workbooks-in-a-folder-using-vba-in-excel/
---

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](https://www.microsoft.com/en-in/microsoft-365/excel)

## Example

- Firstly, you have some **Excel files within a folder** which we want to print.

![](https://geekexcel.com/wp-content/uploads/2021/09/Excel-Files.png)<figcaption>All Excel Files</figcaption>

- 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.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- 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**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Save-the-Code-92-1024x986.png)<figcaption>Save the Code</figcaption>

- 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.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Then, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/Run-the-Code-59.png)<figcaption>Run the Code</figcaption>

- Now, you need to **specify folder path and specify file name** in the Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/Specify-path-and-file-name.png)<figcaption>Specify path and file name</figcaption>

- 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](https://geekexcel.com/)!! **Read more on [**Excel Formulas**](https://geekexcel.com/excel-formula/) **!!**

**Read Next:**

- **[How to use the XNPV function in Excel office 365?](https://geekexcel.com/how-to-use-the-xnpv-function-in-excel-office-365/)**
- **[Excel Formulas to Highlight the Cells that End with Given Value!!](https://geekexcel.com/excel-formulas-to-highlight-cells-end-with/)**
- **[Shortcut for “Select to End of Cell” in the Worksheet!!](https://geekexcel.com/quick-excel-shortcut-for-select-to-end-of-cell-in-a-worksheet/)**
- **[Excel Shortcuts: Delete to the End of Line in the Spreadsheet!!](https://geekexcel.com/shortcuts-for-delete-to-the-end-of-line-in-ms-excel-365/)**
- **[Excel Formulas for Counting Cells that End with certain character or text!!](https://geekexcel.com/excel-formulas-for-counting-cells-that-end-with-certain-character-or-text/)**