Environ Function code samples for VBA

calendar_today Asked Jun 1, 2009
thumb_up 30 upvotes
history Updated April 16, 2026

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)

+30 upvotes ranks this answer #11 out of 81 vba solutions on this site — top 14%.
vba