VBA Microsoft Shell Controls And Automation Library

The Microsoft Shell Controls And Automation Library provides access to Windows Shell objects for scripting purposes.

Note: Late-bound objects do not initialize correctly in this library. Use Early-binding instead.

Classes

Class Description
DFConstraint
DShellFolderViewEvents
Folder Represents a Shell folder.
Folder2 Extends the Folder object to support offline folders.
Folder3
FolderItem Represents an item in a Shell folder.
FolderItems Represents the collection of items in a Shell folder.
FolderItems2 Extends the FolderItems object. InvokeVerbEx method added.
FolderItems3 Extends the FolderItems2 object. Verbs property and Filter method added.
FolderItemVerb Represents a single verb available to an item.
FolderItemVerbs Represents the collection of verbs for an item in a Shell folder.
INewWDEvents Extends the WebWizardHost object by enabling server-side pages hosted in a wizard to verify that the user has been authenticated through a Microsoft account.
IWebWizardHost Enables HTML pages that are hosted in a wizard extension to communicate with the wizard.
IWebWizardHost2
Shell Represents the Shell.
ShellFolderItem Extends the FolderItem object. ExtendedProperty and InvokeVerbEx methods added.
ShellFolderView Represents the objects in a view.
ShellLinkObject Manages Shell links. This object makes much of the functionality of the IShellLink interface available to scripting applications.

Enums and Consts

OfflineFolderStatus
  1. OFS_DIRTYCACHE = 3
  2. OFS_INACTIVE = -1
  3. OFS_OFFLINE = 1
  4. OFS_ONLINE = 0
  5. OFS_SERVERBACK = 2
ShellFolderViewOptions
  1. SFVVO_DESKTOPHTML = 512
  2. SFVVO_DOUBLECLICKINWEBVIEW = 128
  3. SFVVO_SHOWALLOBJECTS = 1
  4. SFVVO_SHOWCOMPCOLOR = 8
  5. SFVVO_SHOWEXTENSIONS = 2
  6. SFVVO_SHOWSYSFILES = 32
  7. SFVVO_WIN95CLASSIC = 64
ShellSpecialFolderConstants
  1. ssfALTSTARTUP = 29
  2. ssfAPPDATA = 26
  3. ssfBITBUCKET = 10
  4. ssfCOMMONALTSTARTUP = 30
  5. ssfCOMMONAPPDATA = 35
  6. ssfCOMMONDESKTOPDIR = 25
  7. ssfCOMMONFAVORITES = 31
  8. ssfCOMMONPROGRAMS = 23
  9. ssfCOMMONSTARTMENU = 22
  10. ssfCOMMONSTARTUP = 24
  11. ssfCONTROLS = 3
  12. ssfCOOKIES = 33
  13. ssfDESKTOP = 0
  14. ssfDESKTOPDIRECTORY = 16
  15. ssfDRIVES = 17
  16. ssfFAVORITES = 6
  17. ssfFONTS = 20
  18. ssfHISTORY = 34
  19. ssfINTERNETCACHE = 32
  20. ssfLOCALAPPDATA = 28
  21. ssfMYPICTURES = 39
  22. ssfNETHOOD = 19
  23. ssfNETWORK = 18
  24. ssfPERSONAL = 5
  25. ssfPRINTERS = 4
  26. ssfPRINTHOOD = 27
  27. ssfPROFILE = 40
  28. ssfPROGRAMFILES = 38
  29. ssfPROGRAMFILESx86 = 48
  30. ssfPROGRAMS = 2
  31. ssfRECENT = 8
  32. ssfSENDTO = 9
  33. ssfSTARTMENU = 11
  34. ssfSTARTUP = 7
  35. ssfSYSTEM = 37
  36. ssfSYSTEMx86 = 41
  37. ssfTEMPLATES = 21
  38. ssfWINDOWS = 36

Use Cases

The Shell32 library can be used to do a number of scripting tasks. Below are some of the possible use cases.

Execute Programs

The ShellExecute method can be used to run an executable program or script.

Public Sub Example()

    Dim ShellApp As Shell32.Shell
    Set ShellApp = CreateObject("Shell.Application")

    ShellApp.ShellExecute "Notepad"

End Sub

Extract From Zip Files

The Shell32 library can be used to extract items from a zip file.

Public Sub ExtractAllFromZipFile(ZipFilePath As String, DestinationPath As String)

    'Requires a reference to the Microsoft Shell Controls And Automation library

    If Dir(ZipFilePath) = "" Then
        Err.Raise 53 'File not found
    End If

    If Dir(DestinationPath, vbDirectory) = "" Then
        Err.Raise 76 'Path not found
    End If

    Dim ShellApp As Shell32.Shell
    Set ShellApp = CreateObject("Shell.Application")

    Dim ZipFolder As Shell32.Folder
    Set ZipFolder = ShellApp.Namespace(ZipFilePath)

    Dim ZipItems As Shell32.FolderItems
    Set ZipItems = ZipFolder.Items

    Dim DestFolder As Shell32.Folder
    Set DestFolder = ShellApp.Namespace(DestinationPath)

    DestFolder.CopyHere ZipItems

End Sub

Access Folder Items

The Shell32 library can be used to iterate over the items in a folder.

Public Sub Example()

    Dim ShellApp As Shell32.Shell
    Set ShellApp = CreateObject("Shell.Application")

    Dim TestFolder As Shell32.Folder
    Set TestFolder = ShellApp.Namespace("C:\Example")

    Dim FI As Shell32.FolderItem
    For Each FI In TestFolder.Items()
        Debug.Print FI.Name
    Next FI

End Sub