Results 1 to 6 of 6

Thread: Run the userforms collection and displaying the form names

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2003
    Posts
    40

    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

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Is this what you want?

    VB Code:
    1. Dim frm As Form
    2.  
    3. For Each frm In Forms
    4.     MsgBox frm.Name & vbCrLf & frm.Caption
    5. Next


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2003
    Posts
    40
    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

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Sorry, I was just guessing with that code...


    Has someone helped you? Then you can Rate their helpful post.

  5. #5
    Lively Member
    Join Date
    Aug 2001
    Posts
    103
    did you find the solution, need it too...
    Last edited by newbiekea; Oct 3rd, 2003 at 08:59 AM.

  6. #6
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    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:
    1. Private Sub CommandButton1_Click()
    2.     ' Show name and caption fo all open UserForms.
    3.     Dim i As Integer
    4.     For i = 0 To UserForms.Count - 1
    5.         MsgBox UserForms(i).Name & vbCrLf & UserForms(i).Caption
    6.     Next i
    7. 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
  •  



Click Here to Expand Forum to Full Width