Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Just to add to what Bob has said...
The most important thing to learn about userforms is that they are classes, each one being a class in its own right (one class of type Userform1, another class of type Userform2 etc). You may have multiple instances of the same class e.g. Option Explicit Private m_FormA As UserForm1 Private m_FormB As UserForm1 Private m_FormC As UserForm1 Private Sub Workbook_Open() Set m_FormA = New UserForm1 m_FormA.Show vbModeless Set m_FormB = New UserForm1 m_FormB.Show vbModeless m_FormB.Move _ m_FormA.Left + 20, m_FormA.Top + 20 Set m_FormC = New UserForm1 m_FormC.Show vbModeless m_FormC.Move _ m_FormB.Left + 20, m_FormB.Top + 20 End Sub Classes have 'members': properties, methods and events. If you want a variable defined in an instance of a class to be made available externally, use a public property e.g. Option Explicit Private m_strUsername As String Public Property Get Username() As String Username = m_strUsername End Property Public Property Let Username(ByVal Newvalue As String) m_strUsername = Newvalue End Property If you want the property to be read-only, omit the Property Let. I will always advise against using public variables but they are *particularly* unsuitable for classes because they behave differently (counterintuitively) from public variables in standard modules. More details he http://msdn.microsoft.com/library/de...assmodules.asp Briefly, using a public variable only saves you writing your own Property Get/Let pair and thus gives you less flexibility. A most challenging aspect is how to make one instance of the class aware of the value of a property in another instance of the same class. Where to get a good discussion about userforms? Right here of course! Jamie. -- |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
user forms | Excel Discussion (Misc queries) | |||
Using multiple user forms to perform Calculations | Excel Programming | |||
VB user forms | Excel Programming | |||
User Forms | Excel Programming | |||
User forms in VBA | Excel Programming |