VBA GetSpecialFolder

The FileSystemObject VBA GetSpecialFolder function returns the path to the specified special folder (Windows, System or Temporary folder).
This function is especially useful if you are looking for a directory to create temporary processing files to avoid creating junk files in default user folders.

VBA GetSpecialFolder Syntax

fso.GetSpecialFolder( folderconstant )

folderconstant
One of 3 values (constants):

Folder Value Description
WindowsFolder 0 Windows folder usually “C:\Windows”
SystemFolder 1 System folder usually containing libraries, fonts, device drivers this is usually “C:\Windows\System32”
TemporaryFolder 2 Temporary user folder. This is usually “C:\Users\user name\AppData\Local\Temp”

In case you have not referenced Microsoft Scripting Runtime library in VBA Project use 0-2 values instead.

VBA GetSpecialFolder Examples

'Late Binding (w/o referencing Microsoft Scripting Runtime)
Set fso = CreateObject("Scripting.FileSystemObject")
fso.GetSpecialFolder(1) 'Result: "C:\Windows\System32"

'Early Binding (referencing Microsoft Scripting Runtime)
Dim fso As FileSystemObject
Set fso = New FileSystemObject
fso.GetSpecialFolder(WindowsFolder) 'Result: "C:\Windows"