Import module via vba instructions

Thomas33

New Member
Joined
Aug 9, 2013
Messages
6
Hi everyone,

I'm working on MS Excel 2010 and trying to have a macro duplicating a sheet(and it's associated macro "Update") in another workbook.

I manage to do almost everything except to import the required module "Update" from a precise and static folder ("Ressource" located in the same folder as all the workbooks) into my active workbook, which is surely possible. If you know about the required instructions, it would very kind of you to help me.

Moreover if you know a way to check if a module already exists and in that case overwrite it, I'd be even more grateful. Presently I just skip the error if it exists.

Here is my actual code:

Code:
 On Error GoTo ErrImport
ErrImport:
If Err.Number = 1004 Then
    MsgBox ("Already there")
    Resume Next    
End If

    Dim Path As String, MacroName as String
    
    Path = ThisWorkbook.Path & "\Ressource\"

    Application.VBE.ActiveVBProject.VBComponents.Import (Path & "Update.bas")
        
    On Error GoTo 0
   
    'Bonus: easy way to add a button and assign Macro to it
    
    AddM.CreateButton
    ActiveSheet.Shapes.Range(Array("Update")).Select
    MacroName = ActiveWorkbook.name & "!Update.Update"
    
    Selection.OnAction = MacroName

Thanks a lot!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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