You can declare variables within the userform class and reference them that way.
Code in standard code module
Sub x()
Dim frmX As UserForm1
Set frmX = New UserForm1
With frmX
.MyProperty = "Hello"
.MyVariable = "World"
.Show
MsgBox .MyProperty & " " & .MyVariable
End With
Unload frmX
Set frmX = Nothing
End Sub
Userform, with a single commandbutton
Public MyVariable As String
Private m_strMyProp As String
Public Property Get MyProperty() As String
MyProperty = m_strMyProp
End Property
Public Property Let MyProperty(RHS As String)
m_strMyProp = RHS
End Property
Private Sub CommandButton1_Click()
Me.Hide
End Sub
Bookmarks