SYMPTOMS
When you refer to the UserForms collection in a Visual Basic for
Applications macro, you may receive one of the following error messages:
Run-time error '13':
Type mismatch
Run-time error '9':
Subscript out of range
WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either
expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes
that you are familiar with the programming language being demonstrated and the
tools used to create and debug procedures. Microsoft support professionals can
help explain the functionality of a particular procedure, but they will not
modify these examples to provide added functionality or construct procedures to
meet your specific needs. If you have limited programming experience, you may
want to contact a Microsoft Certified Partner or the Microsoft fee-based
consulting line at (800) 936-5200. For more information about Microsoft Certified
Partners, please visit the following Microsoft Web site:
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
To refer to a UserForm within a UserForms collection and return a property
or method for the UserForm, use either of the following methods.
Method 1: Create a UserForm Object
The following subroutine displays a UserForm that already is
created.
Sub ShowForm()
'Create an object called "x" to refer to UserForm1.
set x = VBA.UserForms.Add("UserForm1")
'Display the name of UserForm1.
MsgBox x.Name
'Show UserForm1.
x.Show
End Sub
Method 2: Refer Directly to the UserForm
The following two statements display a UserForm that already is created:
VBA.UserForms.Add("UserForm1").Show
Method 3: Reference the Item Property (index) of the UserForm
The following subroutine displays a UserForm that already is created.
Sub ShowForm()
'Open UserForm1 into memory.
Load UserForm1
'Count the loaded UserForms and subtract one
'because UserForm indexes start at zero.
x = UserForms.Count - 1
'Show UserForm1.
UserForms.Item(x).Show
End Sub
REFERENCES
For more information about the UserForms collection, click the Index tab in
Visual Basic Help, type the following text
and then double-click the selected text to go to the "UserForm Object,
UserForms Collection" topic.