Imported Macro to New Workbook still connected to Template
I am not a programmer but have been given the task to try to record a macro for our company's bonus and merit process. I created a template that would go to all HR locations, domestic and overseas, to format their downloads that occur from two different systems. I've used the macro recorder and modified the code where I could to make it work. But the macro buttons I create on their download sheet (MERIT) remain connected to the Template in order to work.
In the macro I export 3 modules from the Template, select the download sheet (which is the second tab in the template file), and do a copy to a new workbook, then import the 3 modules, which does work. But once the Template is closed, and the MERIT sheet is sent to someone who does not have the Template file, the macro buttons fail as they are looking for the Template file to work. Not sure if the problem is the way I exported and imported the modules, or how the buttons were assigned. Below is the code that recorded to export macros, copy MERIT to new workbook, import macros, and assign first button. Can anyone steer me in the right direction?
ActiveWorkbook.VBProject.VBComponents("module32").Export ("c:\BonusColumnSort.bas")
ActiveWorkbook.VBProject.VBComponents("module33").Export ("c:\MeritColumnSort.bas")
ActiveWorkbook.VBProject.VBComponents("module37").Export ("c:\UnhideColumnsRows.bas")
Sheets("MERIT").Select
Sheets("MERIT").Copy
Application.VBE.ActiveVBProject.VBComponents.Import ("c:\BonusColumnSort.bas")
Application.VBE.ActiveVBProject.VBComponents.Import ("c:\MeritColumnSort.bas")
Application.VBE.ActiveVBProject.VBComponents.Import ("c:\UnhideColumnsRows.bas")
ActiveSheet.Select
Application.CommandBars("Forms").Visible = True
ActiveSheet.Buttons.Add(3957.75, 108.75, 79, 30).Select
Selection.OnAction = "BonusColumnSort"
Selection.Characters.Text = "Bonus" & Chr(10) & "Column Sort"
With Selection.Characters(Start:=1, Length:=17).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With

Hi,
I would recommend, you to add an activex object in your sheet and not a form button.
Form buttons will follow and get linked to the workbooks.
So here is what you do...
1) Create an Active x Button. Use the code provided at the linke below.
http://vba2008.wordpress.com/2008/10/17/adding-an-ole-object-command-but...
2) The in your sheet add a code which is in "BonusColumnSort".
Private Sub CommandButton1_Click()
End Sub
Have a go and let me know.
All the best.