creating and textboxes in ecxcel vba during runtime

Hi. i am trying to create textboxes during runtime, and then naming them.

I have managed to create a single textbox during runtime, however, i cant seem to name it.

what i am trying to do is to create a number of textboxes during runtime, and name them each differently, so i can store values into them.

For i = 0 To 5

Set txtB1 = Controls.Add("Forms.TextBox.1")
txtB1.Name = "chkDemo(i)" ' after assigning name to txtB1, i couldnt seem to include values for the new name
chkDemo(i) = "hihi" ' error appears on this line

Next
I would like to be able to create dynamic textboxes during runtime with each textbox name increasing in value with reference to the for loop.

TextBox1,TextBox2,TextBox3 etc

Add TextBox at runtime

Hi,

There is no need to name TextBox controls when you create them. By default the first created TextBox is named TextBox1, the second one will be TextBox2, and so on.

The following example create five TextBox controls and store values into them:

' ************************* ' ************************* '

Sub AddTxtBoxAtRuntime()

    Dim i As Integer
    Dim oTxtBox As Control

   
    For i = 1 To 5
        Set oTxtBox = Me.Controls.Add("Forms.TextBox.1")

       
        With oTxtBox
            .Left = 5
            .Top = (.Height * (i - 1)) + (5 * i)
            .Text = "Hello-" & i
        End With
    Next i

   
    Set oTxtBox = Nothing

End Sub

' ************************* ' ************************* '

 

And here is what the above subroutine do:

 

Best regards.