Monday, January 22, 2007

Delete all RSS Feeds folders in Outlook 2007

I made the mistake to import my OPML file into Microsoft Outlook 2007 and with several hundreds of feeds I found that there was no way to delete multiple feeds. (Outlook does not support OPML with folders.) So I used some of the sample code for Outlook as a starter and solved it quicker than having to delete them one by one. Here is how to remove them automatically saving the tedious work to remove them manually. Open the VBA IDE using Alt+F11 or Tools>Macro>Visual Basic Editor

In Project1>Microsoft Office Outlook Objects>ThisOutlookSession add this code and run the subroutine DeleteAllRssFeedsFolders (folder path might need to be changed). When deleted they end up in the Deleted Items folder where they easily can be permanently deleted.

Private Function GetFolder(ByVal FolderPath As String) As Outlook.folder
Dim TestFolder As Outlook.folder
Dim FoldersArray As Variant
Dim i As Integer

On Error GoTo GetFolder_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set TestFolder = Application.Session.folders.Item(FoldersArray(0))
If Not TestFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.folders
Set SubFolders = TestFolder.folders
Set TestFolder = SubFolders.Item(FoldersArray(i))
If TestFolder Is Nothing Then
Set GetFolder = Nothing
End If
End If
'Return the TestFolder
Set GetFolder = TestFolder
Exit Function

Set GetFolder = Nothing
Exit Function
End Function

Private Sub DeleteFolders(ByVal oFolder As Outlook.folder)
Dim folders As Outlook.folders
Dim folder As Outlook.folder
Dim foldercount As Integer

On Error Resume Next
Set folders = oFolder.folders
foldercount = folders.Count
If foldercount Then
For Each folder In folders
DeleteFolders folder
End If
End Sub

Sub DeleteAllRssFeedsFolders()
Dim folder As Outlook.folder
Set folder = GetFolder("\\Personal Folders In\RSS Feeds")
If Not (folder Is Nothing) Then
DeleteFolders folder
End If
End Sub

Part 2 of 3

Technorati tags: , ,

Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner