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.
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:
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!
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:
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.
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
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:
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:
Note: This code can only export the macros from normal Module.