How To Copy modules from one workbook to another using VBA in Excel?
Tags: tocopymodulesfromone, vbamacros
Published: 2021-10-12 11:26:02

---
title: How To Copy modules from one workbook to another using VBA in Excel?
published: true
date: 2021-10-11 10:35:44 UTC
tags: ToCopyModulesFromOne,VBAMacros
canonical_url: https://geekexcel.com/how-to-copy-modules-from-one-workbook-to-another-using-vba-in-excel/
---

In this post, we will explain to you how to  **copy modules from one Workbook to another using VBA ** in Excel. Let’s see them below!! Get an 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, 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 need to  **copy and paste the code**  given below.

```
Sub CopyModule(SourceWB As Workbook, strModuleName As String, _
    TargetWB As Workbook)
' copies a module from one workbook to another
' example: 
' CopyModule Workbooks("Book1.xls"), "Module1", _
    Workbooks("Book2.xls")
Dim strFolder As String, strTempFile As String
    strFolder = SourceWB.Path
    If Len(strFolder) = 0 Then strFolder = CurDir
    strFolder = strFolder & "\"
    strTempFile = strFolder & "~tmpexport.bas"
    On Error Resume Next
    SourceWB.VBProject.VBComponents(strModuleName).Export strTempFile
    TargetWB.VBProject.VBComponents.Import strTempFile
    Kill strTempFile
    On Error GoTo 0
End Sub

```

- After that, you have to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/10/Save-the-Code-33.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- Now, 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>

- Finally, after  **running the macro** , you will get output as **copy modules from one Workbook to another** using VBA.

## Conclusion

We hope that this post gives you guidelines on how to  **copy modules from one Workbook to another 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/) **!!**

**Continue Reading:**

- **[How to Remove All Macros within Worksheet or Workbook in Excel?](https://geekexcel.com/how-to-remove-all-macros-within-worksheet-or-workbook-in-excel/)**
- **[How To Use VBA Class Modules in Excel office 365?](https://geekexcel.com/how-to-use-vba-class-modules-in-excel-office-365/)**
- **[Copy a Formula in Excel Office 365 ~ Simple Guide!!](https://geekexcel.com/how-to-copy-a-formula-in-excel/)**
- **[Excel Formulas to Find the Same Date in Next Year ~ Simple Guide!!](https://geekexcel.com/excel-formulas-to-find-the-same-date-in-next-year/)**
- **[How to Copy a Cell Formatting from One Cell to Other Cells in Excel 365?](https://geekexcel.com/how-to-copy-a-cell-formatting-from-one-cell-to-other-cells-in-excel-365/)**