I am copying them using:
Private Sub Addbatch_Click()
'copy last page add new and paste
With Me.Batches
PagesCnt = .count
.Pages(PagesCnt - 1).Controls.Copy
.Pages.Add("Page" & (PagesCnt), "Batch" & (PagesCnt + 1), PagesCnt).Paste
End With
'add sheet to workbook
Application.ActiveWorkbook.Worksheets.Add(after:=Worksheets("Batch " & PagesCnt)).Name = "Batch " & PagesCnt + 1
Call rename
End Sub
The full renaming script is:
Private Sub rename()
Dim box As Object
Dim count As Integer
Dim scode As String
'rename the pasted objects
count = 0
For Each box In Me.Batches(PagesCnt).Controls
count = count + 1
box.Name = Worksheets("Templates").Range("AA" & count) & (PagesCnt + 1)
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
scode = vbNullString
End If
If box.Name = "LaminateMaterial" & (PagesCnt + 1) Then
scode = ""
scode = "Private Sub " & box.Name & "_Enter()" & vbCrLf
scode = scode & "msgbox ""before""" & vbCrLf
scode = scode & "call LaminateMaterial()" & vbCrLf
scode = scode & "msgbox ""after""" & vbCrLf
scode = scode & "End Sub"
'Write code for button
With ThisWorkbook.VBProject.VBComponents("BatchesMaterialsLaminates").CodeModule
.AddFromString (scode)
End With
scode = vbNullString
End If
Next box
End Sub
The range AA is just a list of control names
I don't know much about class modules but as far as I can tell the problem isn't with the controls using the same procedure the copied controls won't use any procedure. But as I say I don't know much about class modules (power programming chapter 29 I may skip ahead and check it out) if you think they will help I'm open to suggestion.
Bookmarks