Hi,

I am trying to write VBA routine from workbook "A" which will copy the VBA subroutines to a workbook "B" (Module 2 in my code). I then want to create a button in Workbook B and assign one of the macro's copied over to this button.

I currently have the following code which does almost everything I want, but it uses the macro from the original (workbook A) module.

    Windows(masterWB).Activate
    ActiveWorkbook.VBProject.VBComponents("module2").Export ("C:\mod2.bas")
    Windows(outputWB).Activate
    ActiveWorkbook.VBProject.VBComponents.Import ("C:\mod2.bas")
    Kill ("C:\mod2.bas")
    
    Sheets.Add
    Sheets("Sheet4").Select
    ActiveSheet.Buttons.Add(31.5, 24.75, 72, 72).Select
    Selection.OnAction = "create_charts"

How do i get the macro button to use the local module, not the original module? Note, the new workbook is created dynamically so its name will vary (Stored in "outputWB" in my code).

Thanks in advance for any assistance.