Поделиться через


HOWTO: Delete a Outlook Search Folder programatically

Search folders are very useful but there is no way available using Outlook Object Model to delete them, you need CDO to delete them.

Below code can help you remove the SearchFolders from Outlook

 Function RemoveSearchFolder(ByVal strProfile, ByVal strFolderName As String) As Boolean 

Const CdoPR_FINDER_ENTRYID = &H35E70102 
Dim objSession As MAPI.Session 
Dim objInfostore As MAPI.InfoStore 
Dim objFinderFolder As MAPI.Folder 
Dim objFolder As MAPI.Folder 
Dim strFinderEntryID As String


Set objSession = New MAPI.Session

objSession.Logon ProfileName:=strProfile, ShowDialog:=False

Set objInfostore = objSession.GetInfoStore(objSession.Inbox.StoreID)
strFinderEntryID = objInfostore.Fields.Item(CdoPR_FINDER_ENTRYID).Value
Set objFinderFolder = objSession.GetFolder(strFinderEntryID, objInfostore.ID)

For Each objFolder In objFinderFolder.Folders
    If LCase(strFolderName) = LCase(objFolder.Name) Then
        objFolder.Delete
        RemoveSearchFolder = True
        Exit Function
    End If
Next

objSession.Logoff
End Function

Comments

  • Anonymous
    June 10, 2009
    Vikas: This code only changes the target search folder in the search folders folder in Outlook to italics, but does not appear actually to delete the folder; i.e., one cannot create a new search folder with the same name after this routine has been run on the target search folder. Any thoughts on how really to delete the target search folder (in Outlook 2003)? Thanks, Nick De Lancie