Batch export/import of modules

VBAProIWish

Well-known Member
Joined
Jul 6, 2009
Messages
1,027
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I have a WB with about 80 modules in it. I want to take around 30 of them and put them into another user's WB.

I know that I can export each individual module from MY WB and then import each individual module to THEIR WB which will be very time-consuming. I'm thinking that there must be a faster way.

Is there a way to highlight only the modules you want to export and then "package them together" so that I can simply export and then import them as a "package"?

Thanks
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Here is my suggestion

Sub ExportMods exports all modules and makes a list in Column B

Open the workbook into which you wish to import the modules.
Paste the list in Column B
Run ImportMods

Some things you need to do

  • Edit the path from C:\Temp
  • Edit the list for the correct modules
  • Backup
  • Test
  • Test

Code:
Option Explicit
Sub ExportMods()
    Dim i As Integer
    With ActiveWorkbook.VBProject.VBComponents
        For i = 1 To .Count
            Range("A1").Offset(i - 1, 0).Value = .Item(i).Type
            Range("A1").Offset(i - 1, 1).Value = .Item(i).Name
            .Item(i).Export "C:\Temp\" & .Item(i).Name & ".bas"
        Next i
    End With
End Sub
Sub ImportMods()
Dim x
    With ActiveWorkbook.VBProject.VBComponents
        For i = 0 To WorksheetFunction.CountA(Range("A:A")) - 1
            .import "C:\Temp\" & Range("B1").Offset(i, 0).Text & ".bas"
        Next i
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,277
Messages
6,171,149
Members
452,382
Latest member
RonChand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top