Tuesday, July 20, 2010

reading environment variable values from the excel vba

Environ Function

Returns the String associated with an operating system environment variable. Not available on the Macintosh

Syntax

Environ({envstring | number})
The Environ function syntax has these named arguments:

Part Description
envstring Optional. String expression containing the name of an environment variable.
number Optional. Numeric expression corresponding to the numeric order of the environment string in the environment-string table. The number argument can be any numeric expression, but is rounded to a whole number before it is evaluated.

Remarks

If envstring can't be found in the environment-string table, a zero-length string ("") is returned. Otherwise, Environ returns the text assigned to the specified envstring; that is, the text following the equal sign (=) in the environment-string table for that environment variable.

If you specify number, the string occupying that numeric position in the environment-string table is returned. In this case, Environ returns all of the text, including envstring. If there is no environment string in the specified position, Environ returns a zero-length string.



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

ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\nbdyvek\Application Data
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=B0024811EE6F0
ComSpec=C:\WINNT\system32\cmd.exe
DEFLOGDIR=C:\Documents and Settings\All Users\Application Data\McAfee\DesktopProtection
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\nbdyvek
LOGONSERVER=\\ASIGGNDCS00
LSERVRC=C:\Program Files\Common Files\Mercury Interactive\License Manager\lservrc
LSHOST=172.23.3.194
NUMBER_OF_PROCESSORS=4
OS=Windows_NT
Path=C:\Program Files\Microsoft Office\Office12\;c:\Program Files\oracle\product\10.2.0\client_1\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;"C:\Program Files\PKWARE\pkzipc"
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 23 Stepping 10, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=170a
ProgramFiles=C:\Program Files
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINNT
TEMP=C:\DOCUME~1\nbdyvek\LOCALS~1\Temp
TMP=C:\DOCUME~1\nbdyvek\LOCALS~1\Temp
USERDNSDOMAIN=ASIA.BANKOFAMERICA.COM
USERDOMAIN=ASIA
USERNAME=nbdyvek
USERPROFILE=C:\Documents and Settings\nbdyvek
VSEDEFLOGDIR=C:\Documents and Settings\All Users\Application Data\McAfee\DesktopProtection
WecVersionForRosebud.E88=3
windir=C:\WINNT

No comments:

Post a Comment