Create a module-level variable that can be used by any procedure (sub or function) within a module

Article contributed by Bill Coan

Any code outside a procedure is referred to as module-level code.

Place the following code at the start of a code module (say, NewMacros) and run each subroutine in turn.

Dim myString As String

Sub Test()
    myString = "Hello"
End Sub

Sub Test2()
    myString = "Goodbye"
End Sub

Sub Test3()
    MsgBox myString
End Sub

Click to view Terms of Use page

Click to view Disclaimer page