Copy items from one page to another in multi-page mode using VBA in Excel

I have multipage in a custom form. At run time, the user can add x the number of pages at any time. The elements of each page will be the same. I am wondering if there is a way to duplicate these elements, or will I need to recreate the same elements for each new page? If so, how do I indicate the places on the page where the item should be placed?

enter image description here

+5
source share
2 answers

The trick is to put all the controls in a frame on the 1st page, and then the rest will become easier :)

Page1 Page2 Page2 .

Option Explicit

Private Sub CommandButton2_Click()
    Dim l As Double, r As Double
    Dim ctl As Control

    MultiPage1.Pages.Add

    MultiPage1.Pages(0).Controls.Copy
    MultiPage1.Pages(1).Paste

     For Each ctl In MultiPage1.Pages(0).Controls
        If TypeOf ctl Is MSForms.Frame Then
            l = ctl.Left
            r = ctl.Top
            Exit For
        End If
    Next

    For Each ctl In MultiPage1.Pages(1).Controls
        If TypeOf ctl Is MSForms.Frame Then
            ctl.Left = l
            ctl.Top = r
            Exit For
        End If
    Next
End Sub

enter image description here

+7

" " -2147417949 (80010108) " , - . .

0

All Articles