I have a code which exports a module from a source workbook ("Directory Creation Test.xlsm"), then imports it to a new workbook, assigning he module to a button in the new book. The problem I am having is that when I click the button, the code from the source workbook is used instead. I need the selection.onaction part of the code to select specifically the module in the new workbook. Here's what I have so far:
Running this code, I get run-time error 438: Object doesn't support this property or method, and seems to indicate that the Selection.OnAction line is the issue. Where is my code wrong?
Code:
Dim FName As String
FName = Range("A1") & ".xlsm"
Workbooks.Add.SaveAs Filename:="C:\Folders\" & FName, FileFormat:=52
Workbooks("Directory Creation Test").VBProject.VBComponents("Module6").Export Filename:=("C:\Folders\Modules\ReturnData.bas")
Workbooks(FName).VBProject.VBComponents.Import ("C:\Folders\Modules\ReturnData.bas")
ActiveSheet.Buttons.Add(100, 100, 47.25, 47.25).Select
Selection.OnAction = Workbooks(FName) & "!ReturnData2"
Selection.Characters.Text = "Return Data"
Running this code, I get run-time error 438: Object doesn't support this property or method, and seems to indicate that the Selection.OnAction line is the issue. Where is my code wrong?