Article ID: 187713
Article Last Modified on 9/11/2002
Property Value
-------------------------------
Name cmdNewForm
Caption create new instance
Middle Command Button:
Property Value
----------------------------
Name cmdFormCaption
Caption UserForm caption
Bottom Command Button:
Property Value
----------------------
Name cmdClose
Caption close form
Option Base 1
' Counter for instances of UserForms.
Public mycount As Integer
' Array containing UserForm objects.
Public MyForms() As UserForm1
Sub New_UserForms()
' Display the UserForm.
UserForm1.Show
End Sub
Private Sub cmdNewForm_Click()
mycount = mycount + 1
' Increase the size of the MyForms array by one.
ReDim Preserve MyForms(mycount)
' Create a new instance that is of type UserForm1.
Set MyForms(mycount) = New UserForm1
' Set the caption of the UserForm to the instance number.
MyForms(mycount).Caption = "instance " & mycount
MyForms(mycount).cmdClose.Caption = "hide form"
' Add new item to the list box.
UserForm1.ListBox1.AddItem mycount
End Sub
Private Sub cmdFormCaption_click()
' Display the Caption of the current UserForm.
MsgBox Me.Caption
End Sub
Private Sub cmdClose_Click()
' Hide the current instance of the UserForm.
Me.Hide
End Sub
Private Sub ListBox1_MouseUp _
(ByVal Button As Integer, ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
' Display the selected instance of the UserForm.
MyForms(UserForm1.ListBox1.ListIndex + 1).Show
End Sub
Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)
On Error Resume Next ' Ignore if no forms exist.
' Setting the value of Cancel to any integer other than 0 prevents
' you from clicking the Close ("X") button to close the UserForm.
Cancel = 1
End Sub
120802 Office: How to Add/Remove a Single Office Program or Component
Additional query words: XL98
Keywords: kbhowto kbprogramming KB187713