Is it possible to share a single variable amongst various modules within a Excel VBA Macro? I am trying to write a code in which I read a value from a user form text box and then parse the text in a another module. The code below is a simplified version of what I want to do:
The first part is the user form module:
Public text As String
Public Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Enter As Integer)
If KeyCode = 13 Then
text = TextBox1.Value 'Name of text box.
Logincode
Unload Me
End If
End Sub
While in the second module my code is as follows:
Sub Logincode()
MsgBox text
End Sub
However when I run the code my message box comes up blank. Is it possible to have data for the variable "text" shared by both modules.