Environment Variable Names

G

Guest

Excel 2003. I am using the Environ function to return the "UserName"
environment variable (i.e., Environ("UserName")). Where would I find a
listing of the other environment variables avaiable for use with the Environ
function? Or put another way, what other environment variables can I use
with the Environ function? Thanks and God bless.
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org
 
C

Chip Pearson

Run the following code. It will but the name of the environ
variable in column A and the value in column B.

Sub ListEnvioron()
Dim Rng As Range
Dim Ndx As Long
Dim S As String
Dim Pos As Long

Ndx = 1
On Error Resume Next
Set Rng = Range("A1")
Do While True
S = Environ(Ndx)
If Err.Number <> 0 Then
Exit Do
End If
Pos = InStr(1, S, "=")
Rng.Value = Left(S, Pos - 1)
Rng(1, 2).Value = Mid(S, Pos + 1)
Ndx = Ndx + 1
Set Rng = Rng(2, 1)
Loop
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



message
news:D[email protected]...
 
G

Guest

Try:

Sub xx()
Set ws = CreateObject("WScript.Shell").Environment
For Each Item In ws
Debug.Print Item
Next
Set ws = Nothing
End Sub


Debug.Print Item will list each environment variable in the Immediate
Window; you need to ensure it is visible OR change the code to return the
result in a string.
The immediate Window should have something like this

.....
PROCESSOR_REVISION=0806
TEMP=%SystemRoot%\TEMP
TMP=%SystemRoot%\TEMP
WIN32DMIPATH=c:\dmi\win32
windir=%SystemRoot%
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top