Copy MULTIPLE VBA Modules from 1 file to another. HOW?

Mister H

Well-known Member
Joined
Mar 6, 2002
Messages
1,507
Hi All:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Can anyone tell me if there is a QUICK way of copying multiple modules from one spreadsheet to another?<o:p></o:p>
<o:p></o:p>
I have a spreadsheet called Project and I need to copy a Module and the 2 within it plus a Class Module (whatever that is) and the 12 modules within it. As well I have a User Form and 1 module within it.<o:p></o:p>
<o:p></o:p>
Is there a way of copying all of these to a new another spreadsheet that is currently titles NEW <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:stockticker w:st="on">ADI 1</st1:stockticker>? The file NEW <st1:stockticker w:st="on">ADI 1</st1:stockticker> also has multiple sheets and codes within it so my easiest is to copy all the info from the spreadsheet titled Project to the sheet titled NEW <st1:stockticker w:st="on">ADI 1</st1:stockticker>.<o:p></o:p>
<o:p></o:p>
From what I have found so far it seems that I will need to copy (export) these modules one at a time and then import them to the other spreadsheet. Correct?<o:p></o:p>
<o:p></o:p>
Also, if that is what I need to do can I do the same with the user form?<o:p></o:p>
<o:p></o:p>
I am hoping there might be a VBA to accomplish all of the above because once I have copied the modules and forms to NEW <st1:stockticker w:st="on">ADI</st1:stockticker> 1 I need to do the same for NEW <st1:stockticker w:st="on">ADI</st1:stockticker> 2 thru 15 :banghead:
<o:p></o:p>
Anyway, I don't want to Export and Import one at a time if I don't have to :biggrin:

THANKS for your assistance,<o:p></o:p>
Mark :)<o:p></o:p>
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi tlowry:

THANKS for the link. I will try and implement the code you wrote in the link. HOPEFULLY I can get it to work for me. I will report back so others with the same question can access your solution.

Take Care,
Mark :)
 
Upvote 0
Me AGAIN :)

Can you tell me off hand if there is a difference between Modules and Class Modules? When I import the modules into the New Files should I place the Class Modules back into a Class Module folder?

When I export it grabbed ALL the VBA Modules. I don't want to mess up the codes when I Import them so if they need to be in a Class Module that is where I will put them.

At first glance this code is looking AWESOME :beerchug:
THANKS Again,
Mark
 
Upvote 0
Here's some code:

Code:
Sub xxx()
    Const vbext_ct_ClassModule = 2
    With ActiveWorkbook.VBProject.VBComponents
        For i = 1 To .Count
            Select Case .Item(i).Type
                Case vbext_ct_ClassModule
                    MsgBox "Class module: " & .Item(i).Name
                Case Else
    '                MsgBox "Not a class module: " & .Item(i).Name
                End Select
        Next i
    End With
End Sub
 
Upvote 0
Hi:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
THANKS for the reply. I tried out the previous code that you had referred me to and when I Imported it put the Class Modules back into a Class Modules folder so I kind of jumped the gun. The only thing I will mention for anyone trying the code that is VBA is that the Import code needs to be in the actual spreadsheet that you want to import to. I had tried placing it in my Personal macros and received an error. Of course if you are not VBA Illiterate like me you probably won't try that :)

The only other thing that I could see that did not function properly was that when I Exported all the modules it turns out that there was code on the individual sheets as well. Anyway, it Exported them (identified as 100 in Column A and Sheet name in column B) but when I ran the import it put all of these codes into the Class Modules VBA folder. No Biggie I can cut and paste them to the proper area but I just thought I would mention that.<o:p></o:p>
<o:p></o:p>
Other then the minor things above the code is AWESOME and will save me a ton of work.<o:p></o:p>
<o:p></o:p>
THANKS tlowry your assistance and code are VERY much appreciated

<o:p></o:p>
Take Care,
Mark
 
Upvote 0
I trust you will find this useful. In good ol' 2017, the easiest way to do this, at least for me, is by using MZTools. It is as simple as File --> Export Files. Then File --> Import Files. Done.

Quite a time saver

Download from:
https://www.mztools.com/

From the help file:
The Export Files feature allows you to export all the classes, modules and userforms of a VBA project to a folder (the VBA editor only allows to export the files one by one using the File | Export File... menu or the Export File... context menu of a file in the Project Explorer).

MZ-Tools offers the following ways to export all the files:

The File | Export Files... menu.

The Export Files... context menu in the Project Explorer.

The keyboard shortcut associated with the Export Files feature.
The Import Files feature allows you to import all the classes, modules and userforms from a folder to a VBA project (the VBA editor only allows to import the files one by one using the File | Import File... menu or the Import File... context menu of a file in the Project Explorer).

MZ-Tools offers the following ways to import all the files:

The File | Import Files... menu.

The Import Files... context menu in the Project Explorer.

The keyboard shortcut associated with the Import Files feature.
 
Upvote 0

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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