How do I access the userforms collection?
I have searched everywhere with out any success
Graham
How do I access the userforms collection?
I have searched everywhere with out any success
Graham
Hi Graham,
Correction!
Try following approach:
Public uf1
Sub StartDemo()
Dim ufID() As Integer
Dim vIndex As Integer, Counter As Integer
Dim vModule As Object
For Each vModule In ThisWorkbook.VBProject.VBComponents
' vModule will be:
' = 100 for a Code Module
' = 1 for a standard Code Module
' = 2 for a Class Module
' = 3 for a Userform Module
Debug.Print vModule.Name, Counter
If vModule.Type = 3 Then
vIndex = vIndex + 1
ReDim Preserve ufID(vIndex)
ufID(vIndex) = Counter
End If
Counter = Counter + 1
Next vModule
Choice = InputBox("Enter a number from 1 to " & UBound(ufID))
Set uf1 = ThisWorkbook.VBProject.VBComponents.Item(ufID(Choice) + 1)
' uf1.Designer.Controls("TextBox1").Value = "UF1 Textbox"
uf1.Designer.Controls.Add("forms.TextBox.1") = "UF1 Textbox"
' uf1.Show
VBA.UserForms.Add(uf1.Name).Show
End Sub
Author: Unknown but it´s not me!
Thanks Dennis
That was quick and gives me a starting point
Graham
Ghaham
You´re welcome
Don’t have an account yet? Register yourself now and be a part of our community!