I've created some VBA code to create new workbook, spawn some worksheet elements and import a code module.
Then I want to link the button to the macros in the newly created file using those imported modules.
Instead VBA is trying to assign the button of the newly created file to the macros in the workbook running the code, rather than the destination file itself.
I'm using a line:
destwb.Worksheets(newSheetName).Shapes("Button 1").OnAction = "Test_Button_Press"
Where destwb is the new workbook object and newSheetName is the name of the sheet in this new book containing these elements.
Is there some code that I can use to replace "Test_Button_Press" with something more explicit of the workbook then its codename? i.e. destwb."Test_Button_Press" sort of thing.
Try using:
So that the OnAction string includes the name of the new workbook, an exclamation mark and then the name of the macro.