Skip to main content

How to export all macros from one workbook to another workbook?

If you need to export multiple macro vba codes from one workbook to another, you can copy them one by one normally. But this will be time-consuming, this article, I will talk about how to quickly export all macros from one workbook to another and save the macro files to a specific folder as well.

Export all macros from one workbook to another with VBA code


Export all macros from one workbook to another with VBA code

To export all macro vba codes from one Excel file to another, please do with following steps:

1. First, you should open the two workbooks at the same time, one contains macros, the another is the one you want to export macros to, see screenshot:

doc export macros 1

Office Tab-Open, read, edit, and manage multiple Office documents in a single tabbed window

Office Tab enables tabbed browsing, editing, and managing of Microsoft Office applications. You can open multiple documents / files in a single tabbed window, such as using the browser IE 8/9/10, Firefox, and Google Chrome. Click to download and Free trial now!

doc export macros

2. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. Click Insert > Module, and paste the following macro in the Module Window.

VBA code: Export all macros from one workbook to another:

Sub ExportAndImportModule()
Dim xStrSWSName, xSreDWSName As String
Dim xSWS, xDWS As Workbook
xStrSWSName = "old-workbook"
xSreDWSName = "new-workbook"
Dim xFilePath As String
Dim xObjFD As FileDialog
Set xObjFD = Application.FileDialog(msoFileDialogFolderPicker)
 With xObjFD
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count > 0 Then
            xFilePath = .SelectedItems.Item(1)
        Else
            Exit Sub
        End If
End With
On Error GoTo Err1
Set xSWS = Workbooks(xStrSWSName & ".xlsm")
Set xDWS = Workbooks(xSreDWSName & ".xlsm")
Set xvbap = xSWS.VBProject
Set xVBC = xvbap.VBComponents
For Each Module In xSWS.VBProject.VBComponents
If Module.Type = vbext_ct_StdModule Then
Module.Export (xFilePath & "\" & Module.Name & ".bas")
xDWS.VBProject.VBComponents.Import (xFilePath & "\" & Module.Name & ".bas")
End If
Next Module
Exit Sub
Err1:
    MsgBox "come to nothing!"
End Sub
Note: In the above code, “old-workbook” is the name of workbook which you want to export the macros from, and “new-workbook” is the workbook that you want to import the macros. You should change the names to your own. Both of the two workbooks should be xlsm file format.

doc export macros 2

4. After pasting the above code, then press F5 key to run this code, and a Browse window is displayed, please choose a folder to put the exported macro files, see screenshot:

doc export macros 3

5. Then click OK button, and all macros have been exported from your specified workbook to another Excel file, and the macro files have been saved into the specific folder as well. See screenshot:

doc export macros 4

Note: This code can only export the macros from normal Module.

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (3)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I agree with Rediflow. Please provide a clue to where the code can be found to export all macros from the personal.xlsb file to a text file.
This comment was minimized by the moderator on the site
can this be altered to just export all Moduls from the personal.XLSB? Just for regular "Backup of my Macros" - Reasons
This comment was minimized by the moderator on the site
Hello, This did not work for me:( All my macros have names, is that the problem?Thanks for any help
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations