Zari_the_girl
New Member
- Joined
- Nov 30, 2016
- Messages
- 4
Dear VBA programmers,
I've searched all over the internet but have not yet found the solutions to the following issue:
I want to dynamically get the value of global variables by dynamically using the variable name.
So imagine there are global variables defined in a VBA Excel application (add-in) e.g.,
Public gsTestString as String
Public gsAnotherTest as String
etc etc.
that have values assigned to them at some point in some module, e.g.
gsTestString = "Hello"
gsAnotherTest = "Please help"
Now I want to make a function where one can enter the name of the global variable (as a string) and get the value of that variable back.
So for instance making a function GetVariableValue where GetVariableValue("gsTestString") would return "Hello", but GetVariableValue("gsAnotherTest") would return "Please help".
I don't want to put all variables and their values in arrays or anything similar, as the application has lots of different variables over different modules so putting all of those in arrays would be far from ideal.
Does anybody know how to refer to a variable if you only have its name in a String?
Thanks a lot in advance!
I've searched all over the internet but have not yet found the solutions to the following issue:
I want to dynamically get the value of global variables by dynamically using the variable name.
So imagine there are global variables defined in a VBA Excel application (add-in) e.g.,
Public gsTestString as String
Public gsAnotherTest as String
etc etc.
that have values assigned to them at some point in some module, e.g.
gsTestString = "Hello"
gsAnotherTest = "Please help"
Now I want to make a function where one can enter the name of the global variable (as a string) and get the value of that variable back.
So for instance making a function GetVariableValue where GetVariableValue("gsTestString") would return "Hello", but GetVariableValue("gsAnotherTest") would return "Please help".
I don't want to put all variables and their values in arrays or anything similar, as the application has lots of different variables over different modules so putting all of those in arrays would be far from ideal.
Does anybody know how to refer to a variable if you only have its name in a String?
Thanks a lot in advance!