Hi, long time reader, first time poster.
I have begun using Excel VBA. I have a smattering of experience within various programming languages, but am still coming to terms with the basics of VBA.
I am trying to declare a global variable, assign it a value, then use that global variable.
Within 'ThisWorkbook' I have the following...
...and in the Microsoft Worksheet Object Sheet1 (Sheet1) I have...
Public myText As String
Private Sub Workbook_Open()
myText = "Hi There"
Now, my understanding of this code is that upon opening the workbook, myText variable will be declared, and then assigned the value "Hi There". Then, once I have clicked anywhere on Sheet1, a message box will appear stating "Hi There". Problem is, the message box is blank.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
This is all fine, except I want the message box to state "Hi There". What am I doing wrong?
Is the variable declared (publically) correctly?
Am I assigning the public variable the value correctly?
Am I referencing the public variable correctly in the Worksheet_SelectionChange procedure correctly?
Auto Merged Post;
*sigh* Disregard please.
After 3 straight days of trying out innumerable different things, then finally posting here, the first thing I tried worked.
...must be entered in a Module, not a Microsoft Excel Object, in order for the variable to have global (public) scope.
Public myText as String