Hi everybody!
How can I return a value (String) from a user form?
Thx in Advance!
Stef
Hi everybody!
How can I return a value (String) from a user form?
Thx in Advance!
Stef
The easiest way to do this is to create a Public variable. I suggest creating this variable in the location where you are trying to "pass" it to.
For example, lets say this is the Module you wish to pass the string to, and this module is called "Module1":
Module1 Code:
'This should be put anywheres in the first lines of code in the module
[CODE]Public MyVariable as String
[/CODE]
Userform code:
Hi Stef,
There are two ways.
1. Instead of unloading the userform when the text entry has been made, hide it. You can then access the control values.
For example:
In the userform:
In a general module:
Sub Test()
Dim strTest As String
UserForm1.Show
strTest = UserForm1.TextBox1.Value
MsgBox strTest
End Sub
2. Use a Public variable to hold the string value.
For example:
In the userform:
In a general module:
HTH
Don’t have an account yet? Register yourself now and be a part of our community!