Hello,
What I’m trying to do is assign a macro to a button after it’s been copied from the source workbook.
The module name in the source workbook is “hide”
The macro name is “formatPrint”
I get one of two scenarios
-the button links to the Source workbook instead of the Temp workbook
-the button doesn’t link to anything.
Here’s a snippet of the code with both scenarios
Any ideas ?
What I’m trying to do is assign a macro to a button after it’s been copied from the source workbook.
The module name in the source workbook is “hide”
The macro name is “formatPrint”
I get one of two scenarios
-the button links to the Source workbook instead of the Temp workbook
-the button doesn’t link to anything.
Here’s a snippet of the code with both scenarios
Code:
'Copy the "HIDE" macro to new workbook
Const MODULE_NAME As String = "hide" ' Name of the module to transfer
Const TEMPFILE2 As String = "c:\Modul.bas" ' temp textfile
'** export the module to a textfile
Workbooks(mydatafile).VBProject.VBComponents(MODULE_NAME).Export TEMPFILE2
'import the module to the new workbook
Workbooks(TEMPFILE).VBProject.VBComponents.Import TEMPFILE2
'kill the textfile
Kill TEMPFILE2
‘++++++++++++++++++++
‘This method doesn’t assign anything to the button
With Workbooks(TEMPFILE).Worksheets("sheet1").Buttons.Add(Range("a1").Top, Range("a1").Left, 89.25, 23.25)
.Name = "formatPrint"
.Caption = "Format to Print"
.OnAction = Workbooks(TEMPFILE).Name & "!formatPrint"
End With
‘++++++++++++++++++++
‘This method assigns the code from the source workbook
'Add macro button
Workbooks(TEMPFILE).Worksheets("sheet1").Buttons.Add(Range("a1").Top, Range("a1").Left, 89.25, 23.25).Select
'
Workbooks(TEMPFILE).Worksheets("sheet1").Select
ActiveSheet.Shapes("option button 1").Select
Selection.OnAction = ThisWorkbook.Name & "!printFormat"
Any ideas ?