Question posted 2009 · +15 upvotes
I am looking for some information or code samples for the Environ Function in VBA to grab the username on the current system.
Accepted answer +30 upvotes
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")
3 code variants in this answer
- Variant 1 — 1 lines, starts with
set - Variant 2 — 1 lines, starts with
Environ("username") - Variant 3 — 1 lines, starts with
Environ("userdomain") & "" & Environ("username")
Top vba Q&A (6)
- Difference between Visual Basic 6.0 and VBA +122 (2009)
- VBA – how to conditionally skip a for loop iteration +116 (2011)
- VBA: Test if string begins with a string? +53 (2013)
- html parsing of cricinfo scorecards +47 (2012)
- Code to loop through all records in MS Access +46 (2011)
- Access VBA | How to replace parts of a string with another string +44 (2011)
vba solutions on this site
— top 14%.