Hello, I am trying to call a Private Sub in a form which name is supposed to be generated from another Private Sub in the same form:
Private Sub mysub()
Dim i As Variant
Dim contr As Control
Dim contrname As String
Dim subname As String
Set contr = ActiveControl
contrname = contr.Name
i = Right(contrname, (Len(contrname) - Len("TexTBox"))) 'If the ActiveControl's name in the UserForm is TextBox1 then i = 1
subname = "TextBox" & (i + 5) & "_" & "Enter" 'Call an existing Private sub in the same form which name is TextBox6_Enter ()
Run subname
End Sub
This is the error message I am getting:
Run-time error '1004':
Cannot run the macro "TextBox6_Enter". The macro may not be available in this workbook or all macros may be disabled.
Any help is much appreciated.
Thank you in advance.
Private Sub mysub()
Dim i As Variant
Dim contr As Control
Dim contrname As String
Dim subname As String
Set contr = ActiveControl
contrname = contr.Name
i = Right(contrname, (Len(contrname) - Len("TexTBox"))) 'If the ActiveControl's name in the UserForm is TextBox1 then i = 1
subname = "TextBox" & (i + 5) & "_" & "Enter" 'Call an existing Private sub in the same form which name is TextBox6_Enter ()
Run subname
End Sub
This is the error message I am getting:
Run-time error '1004':
Cannot run the macro "TextBox6_Enter". The macro may not be available in this workbook or all macros may be disabled.
Any help is much appreciated.
Thank you in advance.