Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environ Function code samples for VBA

Tags:

I am looking for some information or code samples for the Environ Function in VBA to grab the username on the current system.

like image 580
gary A.K.A. G4 Avatar asked Jun 01 '09 14:06

gary A.K.A. G4


People also ask

How do I use the Environ function in Excel?

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.

What is Environ temp in VBA?

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.


1 Answers

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")

References

  • Microsoft | Office VBA Reference | Language Reference VBA | Environ Function
  • Microsoft | Office Support | Environ Function
like image 74
Eric Avatar answered Oct 31 '22 00:10

Eric