Oday Salim
Oday Salim

Reputation: 1147

Calling a variable from outside module (VBA)

Is there a clever way of storing variables globally so that you can call them at any of the modules at anytime?

Example

Dim pwd As String
pwd = "password"

Private Sub Test()
    MsgBox (pwd)
End Sub

Thanks

Upvotes: 0

Views: 271

Answers (2)

ComputerVersteher
ComputerVersteher

Reputation: 2696

Your example is a constant.

Public Const pwd as String = "password"

Declare it on top of a standard module.

For other solutions with subs, functions or properties look at the Related-Section on the right side of the page.

Upvotes: 2

ni37osllb
ni37osllb

Reputation: 92

Global pwd As String

inside of a module-level module (not a sheet-level module).

Upvotes: 0

Related Questions