Click to See Complete Forum and Search --> : Run the userforms collection and displaying the form names
J@b@r
Sep 16th, 2003, 11:52 AM
Hello,
I would like to run trough the forms collection and show the name of each form in a messagebox
I do not seem to be able to show the code name of te form on the screen.
Example:
private sub button1_Click()
dim myform as Userform
For each myform in Userforms
msgbox myform.name & vbcrlf & myform.caption
next myform
End sub
manavo11
Sep 16th, 2003, 07:22 PM
Is this what you want?
Dim frm As Form
For Each frm In Forms
MsgBox frm.Name & vbCrLf & frm.Caption
Next
J@b@r
Sep 17th, 2003, 01:25 PM
manavo11,
That is what I mean when you are using VB6.
When I run your code in the Integrated Developement Environment from Excel --> VBA , an error message is shown.
The error message says the defined type does not exist.
The word that is marked is forms.
The only collection I found is Userforms.
It is possible to run trough the Userforms collection.
While you are running trough the Userforms collection it is also possible to show the captions on the userform in a messagebox.
Except the caption seems to be the first line on the userform itself, and not the title in the titlebar.
You can check this by adding the following line to the code inside the for each loop.
--> myform.caption = "Testing"
It also is not possible to show the name of the form in a messagebox.
If you know of a sollution tested in Excel VBA, please post the code.
Thanks in advance,
Greets J@b@r
manavo11
Sep 18th, 2003, 04:13 PM
Sorry, I was just guessing with that code...
newbiekea
Oct 3rd, 2003, 08:50 AM
did you find the solution, need it too...
WorkHorse
Oct 4th, 2003, 10:41 PM
The VBA UserForm is a strange beast. I don't quite understand it. If youv'e ever trie to work with one through API, it looks like hat you have is a wondow that acts as a wrapper or container for the actual UserForm. For whatever reason, when you use a UserForm variable, it seesm to be looking at the UserForm inside the window--so the caption is the UserForm window text (which isn't normally a property of a UserForm) and the UserForm has no Name prperty. But when you refer to the UserForm as an item in the UserForms collection, it appears to be referring to the window wrapper--whch gives you the title bar text.
Private Sub CommandButton1_Click()
' Show name and caption fo all open UserForms.
Dim i As Integer
For i = 0 To UserForms.Count - 1
MsgBox UserForms(i).Name & vbCrLf & UserForms(i).Caption
Next i
End Sub:)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.