View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jon Peltier[_4_] Jon Peltier[_4_] is offline
external usenet poster
 
Posts: 90
Default How to pass values from a userform to a standard module?

Alternatively, Load the userform, populate it however you want to while
still in the main module, then show it. The event that ends the user's
interaction with the UserForm should only hide it, not unload it, so the
main module can unpopulate it. Then the main module unloads the form.

' in the main sub
Load UserForm1
With Userform1
.TextBox1.Text = "Initial Text"
.Show
' now the user is in the userform

' now the user returns from the userform
TextValue = .TextBox1.Text
End With
Unload UserForm1

' in the userform
' change all instances of:
Unload Me
' to this:
Me.Hide

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
http://PeltierTech.com/Excel/Charts/
_______

Colo < wrote:
As another way you can use an argument to pass values to the subroutine
that is in a standard module.


Code:
--------------------

'Userform Module
Private Sub CommandButton1_Click()
Get_Path_and_Filename Me.TextBox1.Text
End Sub

'Standard Module
Sub Get_Path_and_Filename(Optional arg As String)
MsgBox arg & " has been passed"
End Sub

--------------------



---
Message posted from http://www.ExcelForum.com/