Macro that removes,exports & imports modules into 2 different files

Morre

New Member
Joined
Apr 13, 2011
Messages
15
Hi all

I have a master file that requires an update.
This update is situated in a support pack with multiple modules that need to be imported in the master file
When a user loads this support pack the following should happen:
In the master file the module with the same name has to be deleted then the module of the support pack has to be exported. after this the Master most import the exported module.

So far i only have this piece of code.
Function DeleteImportExportModules()

MasterWorkbook = ActiveWorkbook.Name 'Master
MasterWorkbookPath = ActiveWorkbook.Path 'Path of the master
SpWorkbook = "Supportpack.xls" ' Support pack
'
'
ModuleRange = Array("Module1", "Module2","Module3")

For i = 0 To 2
Windows(MasterWorkbook).Activate

Set vbCommomMacros = Application.VBE.ActiveVBProject.VBComponents
vbCommomMacros.Remove VBComponent:= _
vbCommomMacros.Item(ModuleRange(i))

Windows(SpWorkbook).Activate
Activeworkbook.VBProject.VBComponents(ModuleRange(i)).Export (MasterWorkbookPath & "\" & ModuleRange(i) & ".bas")

Windows(Masterworkbook).activate
Application.VBE.ActiveVBProject.VBComponents.Import (SFTWorkbookPath & "\" & ModuleRange(i) & ".bas")

Next i


End Function

Problem is that this code deletes the modules in the support pack and not in the master


Any help is more then welcome

thnx
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
A shot in the dark but shouldn't:-
Code:
Set vbCommomMacros = [COLOR=red][B]Application[/B][/COLOR].VBE.ActiveVBProject.VBComponents
be:-
Code:
Set vbCommomMacros = [COLOR=red][B]ActiveWorkbook[/B][/COLOR].VBE.ActiveVBProject.VBComponents
?

Tip: don't give the modules containing the code which does the updating the same name as the modules containing the application code which is to be updated!

In this case, giving modules different names may highlight exactly what's happening. For example, if the application to be updated contains Module1, Module2 and Module3, and your updater contains Mod_Update, the code will abend if it tries to delete Module1 from the updater and it'll be obvious what's going on. If my suggested code change doesn't fix the problem, try changing the module name in your updater and see where your object variables are pointing when the code fails.
 
Last edited:
Upvote 0
No that is not the problem
Code:
Set vbCommomMacros = Application.VBE.ActiveVBProject.VBComponents

This is correct.

The fact is that the modules need to be replaced allready have different names then the modules that is doing the update. Even in the Master the module that loads the support pack is not beeing deleted
 
Upvote 0
Okay, in that case I've run out of ideas. I've only just started doing this sort of thing myself literally this week.

Have you tried stepping through the code and watching the values of the variables and what your objects are referencing?
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,445
Members
452,915
Latest member
hannnahheileen

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