Search Folders and VBA
Sample CDO function I found that searches for folder by name:
Public Function GetFolderByName( _
ByVal CdoSession As MAPI.Session, _
ByVal strFolderName As String, _
Optional ByVal CdoFolderParent As MAPI.Folder = Nothing, _
Optional ByVal bCreate As Boolean = True _
) As MAPI.Folder
Dim CdoInfoStore As MAPI.InfoStore
Dim CdoFolderRoot As MAPI.Folder
Dim CdoFolders As MAPI.Folders
Dim CdoFolder As MAPI.Folder
Dim bFound As Boolean
' If the parent folder wasn't passed in, then use the root
' folder of the default InfoStore.
If CdoFolderParent Is Nothing Then
' Get the Folders collection from the default InfoStore.
Set CdoInfoStore = CdoSession.GetInfoStore
Set CdoFolderRoot = CdoInfoStore.RootFolder
Set CdoFolders = CdoFolderRoot.Folders
Else
' Get the Folders collection from the parent folder.
Set CdoFolders = CdoFolderParent.Folders
End If
' Loop through the folders in the collection until the
' desired folder is found.
bFound = False
Set CdoFolder = CdoFolders.GetFirst
Do While (Not bFound) And Not (CdoFolder Is Nothing)
If CdoFolder.Name = strFolderName Then
bFound = True
Else
Set CdoFolder = CdoFolders.GetNext
End If
Loop
' If not found, then create it (if caller said to).
If (CdoFolder Is Nothing) And bCreate Then
Set CdoFolder = CdoFolders.Add(strFolderName)
End If
Set GetFolderByName = CdoFolder
' Release our local objects.
Set CdoFolder = Nothing
Set CdoFolders = Nothing
Set CdoFolderRoot = Nothing
Set CdoInfoStore = Nothing
End Function ' GetFolderByName
Does not show Hidden Folders!!
|