Special Folders' Path (VBA)

Vishesh's picture
The following code displays path of all special folders in Windows on the worksheet. Copy the following code in a general module and run(F5).
Sub GetSpecialFolderPaths()
    Dim WSHShell        As Object
    Dim strPath         As String
    Dim strFolderName   As String
    Dim intLoop         As Integer
 
    Set WSHShell = CreateObject("Wscript.Shell")
 
    For intLoop = 0 To WSHShell.SpecialFolders.Count - 1
        strPath = WSHShell.SpecialFolders(intLoop)
        strFolderName = Mid(strPath, InStrRev(strPath, Application.PathSeparator) + 1, 9999)
        ActiveSheet.Cells(intLoop + 1, 1) = strFolderName
        ActiveSheet.Cells(intLoop + 1, 2) = strPath
    Next intLoop
 
    Set WSHShell = Nothing
End Sub