Access system-environment variables

P

Perry

Is there an (easy) way to access those variables displayed using the
dos "set" command from an Excel Macro

Specifically want to target username, userdomain, homedrive.

Thanks
 
N

Norman Jones

Hi Perry,
Is there an (easy) way to access those variables displayed using the
dos "set" command from an Excel Macro

Specifically want to target username, userdomain, homedrive.


Try:

'=============>>
Public Sub ListEnviron()
Dim SH As Worksheet
Dim i As Long
Dim iPos As Long

Set SH = ActiveWorkbook.Sheets.Add

With SH
.Name = "Environ List"
i = 1
While Environ(i) <> ""
iPos = InStr(Environ(i), "")
.Cells(i, "A").Value = i
.Cells(i, "B").Value = "'" & Mid(Environ(i), iPos)
i = i + 1
Wend
.Columns("B:C").AutoFit
End With

End Sub
'<<=============

If you are not familiar with macros, you may wish to visit David McRitchie's
'Getting Started With Macros And User Defined Functions' at:

http://www.mvps.org/dmcritchie/excel/getstarted.htm
 
Top