Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List environment variables

Office / VBA General

List environment variables

by  xlbo  Posted    (Edited  )
This FAQ is simply some code to show all the current environment variables for the current excel session. Environment variables can be used to test for users, homedrives, no. of processors and domains amoungst other things. It works on windows only (sorry mac users) and I use it most often to obtain the network userid of the current user. This is especially useful where you have different types of access depending on who the user is.

This code will show all the environment variables:

Sub List_Environment_Variables()
Dim EnvString As String
Indx = 1
Do
EnvString = Environ(Indx)
Cells(Indx, 1) = EnvString
Indx = Indx + 1
Loop Until EnvString = ""
End Sub


The one I use most is
environ("username")

so you can use

dim myUser as string
myUser = environ("username")

to return the current user's network id
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top