I wish to delete all the folders from the outlook favorites then subsequently replace them, but the delete doesn't seem to work. What's wrong with my code.
Setup Objects works fine
' Get the "Favorite Folders" navigation group
Set favGroup = Application.ActiveExplorer.NavigationPane.Modules.GetNavigationModule(olModuleMail).NavigationGroups.GetDefaultNavigationGroup(olFavoriteFoldersGroup)
This works
Set inboxFldr = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
favGroup.NavigationFolders.Add (inboxFldr)
All this works except the .delete lines (which fail with the error "wrong number of arguments or invalid property assignment) - obviously I only want one delete line, but put both in to show the options I'd tried.
Debug.Print favGroup.NavigationFolders.count
Set oFolder = Application.ActiveExplorer.CurrentFolder
While favGroup.NavigationFolders.count > 0
favGroup(1).Delete
favGroup.NavigationFolders(1).Delete
Wend
You have to use the
Remove
method of theNavigationFolders
collection. It takes aNavigationFolder
as the argument. There is no Delete method.I guess it's this way because you're not really deleting anything. The Inbox, for instance, doesn't get deleted just because you remove it from Favorites. That must be why they use a
Collection.Remove(Collection.Item)
method instead of aCollection.Item.Delete
method.