Environment Variables

Published on July 8, 2010

In many macros you need access active session environment settings like username, computer name, etc. The easiest way to do this is using Windows environment variables. To see what environment variables are available open a Command Prompt window and enter the SET command. Some of the more common examples are shown in the code sample below:

Sub MyMacro()
Dim strUsername As String
Dim strComputername As String
Dim strTempFolder As String
Dim strUserProfile As String

strUsername = Environ$(“USERNAME”)
strComputername = Environ$(“COMPUTERNAME”)
strTempFolder = Environ$(“TEMP”)
strUserProfile = Environ$(“USERPROFILE”)

End Sub

Like this article? Share it!

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Privacy Policy