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
    1. Dim form As UserForm
    2. For Each form In UserForms
    3. Unload form
    4. 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
    1. For Each form In UserForms
    2. If form.Name <> UserForms(LandingPage).Name Then
    3. Unload form
    4. End If
    5. 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
    1. For Each form In UserForms
    2. If form.Name <> "LandingPage" Then
    3. Unload form
    4. End If
    5. 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!