Delete Sub-folder Contents
I am using the following code which deletes the contents of the Deleted items folder. it works perfectly.
Code:
Public Sub EmptyDeletedEmailFolder()
Dim outApp As Outlook.Application
Dim deletedFolder As Outlook.MAPIFolder
Dim item As Object
Dim entryID As String
Set outApp = CreateObject("outlook.application")
Set deletedFolder = outApp.GetNamespace("MAPI").GetDefaultFolder(olFolderDeletedItems)
For i = deletedFolder.Items.Count To 1 Step -1
deletedFolder.Items(i).Delete '' Delete from mail folder
Next
Set item = Nothing
Set deletedFolder = Nothing
Set outApp = Nothing
End Sub
When I try to amend the code to delete a sub folder called MyFolder it keeps throwing a runtime -2147024809 (80070057) error. I have indicated the line that I changed in the code below. Any guidance would be appreciated.
Code:
Public Sub EmptyDeletedEmailFolder()
Dim outApp As Outlook.Application
Dim deletedFolder As Outlook.MAPIFolder
Dim item As Object
Dim entryID As String
Set outApp = CreateObject("outlook.application")
'I changed olFolderDeletedItems to olFolderMyFolder at the end of the next line
Set deletedFolder = outApp.GetNamespace("MAPI").GetDefaultFolder(olFolderMyFolder)
For i = deletedFolder.Items.Count To 1 Step -1
deletedFolder.Items(i).Delete '' Delete from mail folder
Next
Set item = Nothing
Set deletedFolder = Nothing
Set outApp = Nothing
End Sub
Thanks