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
YasserKhalil's picture

How can we make use of such

How can we make use of such code?

special folders

This isn't useful as is since you're referencing the items in the special folders array by their index. If you only want to list them, fine, but it's much nicer to use the special folders name enumeration (provided you know the values). Thanks to TheSmileyCoder at http://bytes.com/topic/access/insights/933853-find-users-special-folders....

Vishesh's picture

Yes, thanks JC this is really

Yes, thanks JC this is really useful.