Hi Sam, Thanks for the answer and yes the way you explain it is known and that already works but what I am looking for is different.
My first explanation was (reading your answer) not correct for which I excuse myself.
The idea is as follows:
I have one Userform which has 10 CommandButtons all with their standard namse CommandButton1, 2, etc 10 (code below)
Option Explicit
Const btnHeight As Long = 42
Private Sub userform_initialize()
Dim xLoop As Integer
Dim uRng As Range
Dim frmH As Long
Dim uForm As Object
For xLoop = 1 To 10
Me.Controls("CommandButton" & xLoop).Visible = False
Next xLoop
xLoop = 0
For Each uRng In Worksheets("Sheet3").Range("USERFORMS") ' This named range contains a dynamic named list of 1 to 10 userform names UserForm1, 2, or other etc and the Offset(0,1) is the actual Caption text to show on the button
xLoop = xLoop + 1
With Me.Controls("CommandButton" & xLoop)
.Visible = True
.Caption = uRng.Offset(0, 1)
.Font.Bold = True
.Tag = "show" & uRng ' the complete text here results "showUserForm1" where 1 goes from 1 to 10 and a macro has to be present in the VBA Project Public Sub showUserForm1()
.Top = 10 + IIf(xLoop = 1, 0, (xLoop - 1) * 52)
End With
frmH = xLoop * 52
Set uForm = Nothing
If xLoop = 10 Then Exit For
Next uRng
frmH = frmH + 35
Me.Caption = "Make your choice"
Me.Height = frmH
End Sub
Private Sub UserForm_Activate()
Me.Left = 50 '(Application.Width / 2) - (Me.Width / 2)
Me.Top = (Application.Height / 2) - (Me.Height / 2) 'btnHeight
Me.BtnEXIT.SetFocus
End Sub
Private Sub BtnEXIT_Click()
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
' This is to force the user to use the Cancel button
If CloseMode = vbFormControlMenu Then
Cancel = True
End If
BtnEXIT.SetFocus
End Sub
Private Sub CommandButton1_Click()
Unload Me
Application.Run (Me.CommandButton1.Tag)
End Sub
Private Sub CommandButton2_Click()
Unload Me
Application.Run (Me.CommandButton2.Tag)
End Sub
' and the rest
Private Sub CommandButton10_Click()
Unload Me
Application.Run (Me.CommandButton2.Tag)
End Sub
All the 10 commandbuttons have a CommandButton?_Click() that will then unload this form and run the macro opening the form
What I am looking for is to place just place the userform name in the .Tag and when the CommanButton?_Click is clicked
just use the Me.CommandButton9.Tag without having to create an extra macro for this
The idea:
Private Sub CommandButton9_Click()
Dim uForm As Userform
Unload Me
set Uform = Me.CommandButton9.Tag
uForm.show
End Sub
I hope this explains my idea.