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