ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Environment Variable Names (https://www.excelbanter.com/excel-programming/359402-environment-variable-names.html)

Chaplain Doug

Environment Variable Names
 
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

Chip Pearson

Environment Variable Names
 
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



"Chaplain Doug" wrote in
message
...
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




AA2e72E

Environment Variable Names
 
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%



"Chaplain Doug" wrote:

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


Chaplain Doug

Environment Variable Names
 
Thanks guys.
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org


"Chaplain Doug" wrote:

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



All times are GMT +1. The time now is 05:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com