EnvVar_All

Read all Environment variables using EnvDir_All
Or quickly get user folder, or appdata folder using EnvDir_User or EnvDir_AppData

Function EnvDir_User()
 EnvDir_User = EnvVar_All("USERPROFILE")
End Function
Function EnvDir_AppData()
 EnvDir_AppData = EnvVar_All("APPDATA")
End Function

Sub EnvVar_All(Optional VarName = "")
 If VarName > "" Then
  EnvVar_All = Environ(VarName)
 Else
  For i = 1 To 255
   strVar = Environ$(i)
   If LenB(strVar) = 0& Then Exit For
   EnvVar_All = EnvVar_All & i & " | " & strVar & vbcrlf
  Next
 End If
End Sub


' Result is:
' 1 | ALLUSERSPROFILE=C:\ProgramData
' 2 | APPDATA=C:\Users\ANmars\AppData\Roaming
' 3 | CommonProgramFiles=C:\Program Files\Common Files
' 4 | CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
' 5 | CommonProgramW6432=C:\Program Files\Common Files
' 6 | COMPUTERNAME=ANMARIO
' 7 | ComSpec=C:\WINDOWS\system32\cmd.exe
' 8 | configsetroot=C:\WINDOWS\ConfigSetRoot
' 9 | FP_NO_HOST_CHECK=NO
' 10 | HOMEDRIVE=C:
' 11 | HOMEPATH=\Users\ANmars
' 12 | LOCALAPPDATA=C:\Users\ANmars\AppData\Local
' 13 | LOGONSERVER=\\MicrosoftAccount
' 14 | NUMBER_OF_PROCESSORS=4
' 15 | OS=Windows_NT
' 16 | Path=C:\Program Files\Microsoft Office\Office14\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;;.;
' 17 | PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
' 18 | PROCESSOR_ARCHITECTURE=AMD64
' 19 | PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 69 Stepping 1, GenuineIntel
' 20 | PROCESSOR_LEVEL=6
' 21 | PROCESSOR_REVISION=4501
' 22 | ProgramData=C:\ProgramData
' 23 | ProgramFiles=C:\Program Files
' 24 | ProgramFiles(x86)=C:\Program Files (x86)
' 25 | ProgramW6432=C:\Program Files
' 26 | PROMPT=$P$G
' 27 | PSModulePath=C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\;c:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\
' 28 | PUBLIC=C:\Users\Public
' 29 | SystemDrive=C:
' 30 | SystemRoot=C:\WINDOWS
' 31 | TEMP=C:\Users\ANmars\AppData\Local\Temp
' 32 | TMP=C:\Users\ANmars\AppData\Local\Temp
' 33 | USERDOMAIN=ANMARIO
' 34 | USERDOMAIN_ROAMINGPROFILE=ANMARIO
' 35 | USERNAME=ANmars
' 36 | USERPROFILE=C:\Users\ANmars
' 37 | VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\
' 38 | WecVersionForRosebud.69180=4
' 39 | windir=C:\WINDOWS

Optional VarName

Views 610 Downloads 219

'File System', 'System', 'Environment', 'Environ', 'variables', 'Windows', 'User', 'profile', 'Dir', 'Folder'

ANmarAmdeen
326
Attachments
File System VBA
Revisions

v1.0