|
-
Sep 16th, 2003, 11:52 AM
#1
Thread Starter
Member
Run the userforms collection and displaying the form names
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
-
Sep 16th, 2003, 07:22 PM
#2
Is this what you want?
VB Code:
Dim frm As Form
For Each frm In Forms
MsgBox frm.Name & vbCrLf & frm.Caption
Next
Has someone helped you? Then you can Rate their helpful post. 
-
Sep 17th, 2003, 01:25 PM
#3
Thread Starter
Member
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
-
Sep 18th, 2003, 04:13 PM
#4
-
Oct 3rd, 2003, 08:50 AM
#5
Lively Member
did you find the solution, need it too...
Last edited by newbiekea; Oct 3rd, 2003 at 08:59 AM.
-
Oct 4th, 2003, 10:41 PM
#6
Fanatic Member
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.
VB Code:
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|