I am looking for some information or code samples for the Environ
Function in VBA to grab the username on the current system.
You can use the ENVIRON function to retrieve the value of an environment variable by providing the numeric position of the variable within the environment variable table. When you supply the numeric position, it will return both the name of the environment variable as well as its value.
The Environ function lets you get the Windows environment variables for the computer your program is currently running on, for example the user name or the name of the temporary folder.
Environ()
gets you the value of any environment variable. These can be found by doing the following command in the Command Prompt:
set
If you wanted to get the username, you would do:
Environ("username")
If you wanted to get the fully qualified name, you would do:
Environ("userdomain") & "\" & Environ("username")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With