Access system-environment variables

  • Thread starter Thread starter Perry
  • Start date Start date
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
 
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
 

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

Back
Top