How To Add Content to a module from a file using VBA in Excel?
Tags: toaddcontenttoamodul, vbamacros
Published: 2021-10-12 01:52:51

---
title: How To Add Content to a module from a file using VBA in Excel?
published: true
date: 2021-10-11 10:09:17 UTC
tags: ToAddContentToAModul,VBAMacros
canonical_url: https://geekexcel.com/how-to-add-content-to-a-module-from-a-file-using-vba-in-excel/
---

In this article, you will learn how to  **add content to a module from a file using VBA**  in Microsoft Excel. Let’s get 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 ImportModuleCode(ByVal wb As Workbook, _
    ByVal ModuleName As String, ByVal ImportFromFile As String)
' imports code to ModuleName in wb from a textfile named ImportFromFile
Dim VBCM As CodeModule
    If Dir(ImportFromFile) = "" Then Exit Sub
    On Error Resume Next
    Set VBCM = wb.VBProject.VBComponents(ModuleName).CodeModule
    If Not VBCM Is Nothing Then
        VBCM.AddFromFile ImportFromFile
        Set VBCM = Nothing
    End If
    On Error GoTo 0
End Sub

```

- 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-34.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 can **add content to a module from a file**  in Excel.

## Summary

We hope that this tutorial gives you guidelines on how to  **add content to a module from a file using VBA**  in Microsoft 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 Ahead:**

- **[How To Delete module content using VBA in Microsoft Excel?](https://geekexcel.com/how-to-delete-module-content-using-vba-in-microsoft-excel/)**
- **[Excel Formulas to Get the content of Given Row and Column!!](https://geekexcel.com/excel-formulas-get-content-given-row-column/)**
- **[How To Delete a procedure from a module using VBA in Excel?](https://geekexcel.com/how-to-delete-a-procedure-from-a-module-using-vba-in-excel/)**
- **[Quick Shortcut to Delete Cells in Microsoft Excel 365!!!](https://geekexcel.com/quick-shortcut-to-delete-cells-in-microsoft-excel-365/)**
- **[Shortcut to Delete Comment in Microsoft Excel 365](https://geekexcel.com/shortcut-to-delete-comment-in-microsoft-excel-365/)**