Compartilhar via


Excluir todos os itens e subpastas na pasta itens excluídos

This topic shows a code sample in Visual Basic for Applications (VBA) that deletes all items and subfolders in the Deleted Items folder.

Nota Ao excluir itens ou pastas de uma coleção, você deve usar um contador de loop decrementing. An incrementing loop counter will fail.

You can only empty the Deleted Items folder and you cannot remove the folder itself. However, to delete subfolders of the Deleted Items folder, you can simply delete the subfolder without first deleting its contents.

Sub RemoveAllItemsAndFoldersInDeletedItems() 
 Dim oDeletedItems As Outlook.Folder 
 Dim oFolders As Outlook.Folders 
 Dim oItems As Outlook.Items 
 Dim i As Long 
 'Obtain a reference to deleted items folder 
 Set oDeletedItems = Application.Session.GetDefaultFolder(olFolderDeletedItems) 
 Set oItems = oDeletedItems.Items 
 For i = oItems.Count To 1 Step -1 
 oItems.Item(i).Delete 
 Next 
 Set oFolders = oDeletedItems.Folders 
 For i = oFolders.Count To 1 Step -1 
 oFolders.Item(i).Delete 
 Next 
End Sub

Suporte e comentários

Tem dúvidas ou quer enviar comentários sobre o VBA para Office ou sobre esta documentação? Confira Suporte e comentários sobre o VBA para Office a fim de obter orientação sobre as maneiras pelas quais você pode receber suporte e fornecer comentários.