Dynamically referencing a userform name

  • Greetings,


    I have an application that uses a series of userforms. One of my subroutines contains code to unload any forms that are currently loaded so as to reset the project:


    Code
    Dim form As UserForm
    
    For Each form In UserForms
        Unload form
    Next form

    The above code works fine. However, I have another sub that is supposed to unload any loaded userforms except a specific one:


    Code
    For Each form In UserForms
        If form.Name <> UserForms(LandingPage).Name Then
        Unload form
        End If
    Next form

    With this code I get the ol' runtime error 438 "Object does not support this property or method". I have also tried it this way with the same result:


    Code
    For Each form In UserForms
        If form.Name <> "LandingPage" Then
        Unload form
        End If
    Next form

    To summarize, I'm trying to unload a series of userforms via a loop, and need to refer to a unique property to avoid unloading a specific userform. It does not appear that I can refer to userform.name in the code (".Name" doesn't even appear as an available property in Intellisense), so I'm wondering how to do this properly.


    Thanks!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!