I have a userform with multipage containing several objects. on this form is a button that adds another page to the multipage copies all of the objects over and renames them (so listbox 1 on page 1 becomes listbox 2 on page 2) as far as I am aware this works (used the msgbox method to check all the names are assigned when the userform is running).
during this rename of the created objects the script writes some macros for the necessary copied objects:
If box.Name = "Addlaminate" & (PagesCnt + 1) Then
        scode = ""
        scode = "Private Sub " & box.Name & "_Click()" & vbCrLf
        scode = scode & "msgbox ""before""" & vbCrLf
        scode = scode & " call addlaminate()" & vbCrLf
        scode = scode & "msgbox ""after""" & vbCrLf
        scode = scode & "End Sub"

        'Write code for button
        With ThisWorkbook.VBProject.VBComponents("BatchesMaterialsLaminates").CodeModule
            .AddFromString (scode)
        End With
the code is written (if I close the form and open the VBA editor I can see it) however it doesn't run when I click the new Addlaminate2 button on multipage page 2 there is no error message there is nothing it is as if there is no code written for the button.

any ideas why this happens and how to fix it?

Regards
Leon