If you want to reference a one particular userform you can do it in a very simple way. What you can do is you can just use the name of the userform. For an example, think you have a userform call UserForm1. If you want to show this userform you can simply use following code.
Sub ShowForm() UserForm1.Show End Sub |
But sometimes we need to reference userforms dynamically. For an example assume you have several userforms. You need to show a different forms depending on different conditions. And there is a text box where program generate the name of the userform you need to display. That means you need to show the userform which is shown in this text box. Then we can't use above simple method. Because we need to reference userforms dynamically. So we need a more dynamic solution like below. Here txtDisplayFormName refers to name of the textbox where program displays the name of the userform we need to show.
Dim formName As String formName = txtDisplayFormName.Value Dim DForm As Object Set DForm = UserForms.Add(formName) DForm.Show |