For anybody looking for this in the future, here's the complete solution using Robin's code (Thanks!), but put in a Class for the pages created at runtime. I'm only pasting the relevant code to this question, the CopyPage procedure can also be called by the user to add pages during runtime. Now the user can also move them left and right between pages 2 (index 1) and n.
In my main module:
Public arrLeftButton() As New CButton
Public arrRightButton() As New CButton
In my CButton Class Module:
Option Explicit
Public WithEvents CopyButton As MSForms.CommandButton
Public WithEvents DeleteButton As MSForms.CommandButton
Public WithEvents MoveLeft As MSForms.CommandButton
Public WithEvents MoveRight As MSForms.CommandButton
Private Sub MoveLeft_Click()
Dim pag As MSForms.Page
Dim lngPageCount As Long
Set pag = UFmodproject.MultiPage1.SelectedItem
lngPageCount = UFmodproject.MultiPage1.Pages.Count
If pag.Index > 1 Then
pag.Index = pag.Index - 1
End If
End Sub
Private Sub MoveRight_Click()
Dim pag As MSForms.Page
Dim lngPageCount As Long
Set pag = UFmodproject.MultiPage1.SelectedItem
lngPageCount = UFmodproject.MultiPage1.Pages.Count
If pag.Index < lngPageCount - 1 Then
pag.Index = pag.Index + 1
End If
End Sub
And my UserForm_Initialize:
Private Sub userform_initialize()
ReDim Preserve arrLeftButton(1 To 1)
ReDim Preserve arrRightButton(1 To 1)
Set arrLeftButton(1).MoveLeft = MultiPage1.Pages(1).Controls("MoveLeft1")
Set arrRightButton(1).MoveRight = MultiPage1.Pages(1).Controls("MoveRight1")
For i = 2 To GetINIString("Project", "NumberOfShipmentTypes", strINIPATH)
Call FormControls.CopyPage
Next
End Sub
Yet in another standard module, so it can be called from elsewhere too:
Sub CopyPage()
Dim l As Double, r As Double
Dim Ctrl As Control
Dim newCtrl As Object
Dim pCount As Long
pCount = UFmodproject.MultiPage1.Pages.Count
'[...add pages and copy all controls]
For Each newCtrl In UFmodproject.MultiPage1.Pages(pCount).Controls
If Left(newCtrl.Name, Len(newCtrl.Name) - 1) = "MoveLeft" Then
ReDim Preserve arrLeftButton(1 To pCount)
Set arrLeftButton(pCount).MoveLeft = newCtrl
End If
If Left(newCtrl.Name, Len(newCtrl.Name) - 1) = "MoveRight" Then
ReDim Preserve arrRightButton(1 To pCount)
Set arrRightButton(pCount).MoveRight = newCtrl
End If
Next
End Sub