VBA to insert feature from Toolbox into the User Form after it is open (shown)

VBA to insert feature from Toolbox into the User Form after it is open (shown)

engilic
Advocate Advocate
472 Views
4 Replies
Message 1 of 5

VBA to insert feature from Toolbox into the User Form after it is open (shown)

engilic
Advocate
Advocate

Hi,

 

VBA, is it possible to insert a feature from Toolbox (label, button, form, ...) after UserForm is open (shown) and how?

 

thank you

0 Likes
473 Views
4 Replies
Replies (4)
Message 2 of 5

Ralf_Krieg
Advisor
Advisor

Hello

 

Afaik no, you must insert it before the form is initialized. But you can use the Visible Property to hide it at start.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 5

engilic
Advocate
Advocate

Thank you @Ralf_Krieg ,

 

thats a pity, I thought to have as many buttons as I want at a certain time by changing the code rather than changing a UserForm.

Now I need to predict what could be the max number of buttons I need, if it was possible to insert them after UF is shown no need for prediction.

 

Hm, I guess it is possible to move them after the UF is shown, so if that is possible I can put them on top of each other, move later and show or hide.

The thing is if there are many buttons needed I would like to have them in two or three rows, then everything under need to move.

 

So the new question is:

 

Is it possible to move objects after UserForm is shown, I guess it is, just change Top and Left, also for size, just change Width and Height?

 

thank you

0 Likes
Message 4 of 5

Ralf_Krieg
Advisor
Advisor

Hello

 

Sorry, i was wrong. Don't know what i was thinking of while writing. 😔

You can do this. An example to add 3 Checkboxes:

Dim a As Integer ' count of checkboxes
a = 0

Dim i As Integer
Dim oChkbox As Control

For i = 1 To 3
    a = a + 1
    With Me.Controls
        Set oChkbox = .Add("Forms.checkbox.1", "Checkbox" & i, True)
        With oChkbox
            .Width = 108
            .Height = 18
            .Top = 20 * a
            .Left = 25
            .Caption = "Number " & a
        End With
    End With
Next i

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 5 of 5

engilic
Advocate
Advocate

Great @Ralf_Krieg , thank you very much,

 

will try it next week.

0 Likes