PC Review


Reply
Thread Tools Rate Thread

Delete all items in Deleted Items folder or Permanently delete a message

 
 
XxLicherxX
Guest
Posts: n/a
 
      6th Jul 2005
Hello everyone,

I am wondering if someone can tell me how I can empty the Deleted Items
Folder using VBA. I have found a few examples on the web, but none of
the have worked.

If this is not possible to do, is they a way to permanently delete them
from the inbox (So the never reach the deleted items folder) ?

Thanks for your help.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?RXJpYyBMZWdhdWx0IFtNVlAgLSBPdXRsb29rXQ==
Guest
Posts: n/a
 
      8th Jul 2005
To permanently delete a message in the Outlook interface, hold down the Shift
key while clicking the Delete button or pressing the Delete key.

To do this with code, you need to use CDO. This macro will permanently
delete the currently selected items:

Sub PermanentlyDeleteSelectedMessges()
On Error GoTo PermanentlyDeleteSelectedMessges_Error

Dim objSession As New MAPI.Session
Dim objSelection As Outlook.Selection
Dim objItem As Object
Dim objMAPIMessage As MAPI.Message 'Requires reference to the Microsoft
CDO 1.21 Library

'To permanently delete currently selected item(s) in active folder
objSession.Logon , , , False
Set objSelection = ActiveExplorer.Selection

If objSelection Is Nothing Or objSelection.Count = 0 Then Exit Sub
For Each objItem In objSelection
Set objMAPIMessage = objSession.GetMessage(objItem.EntryID)
'Permanently delete
objMAPIMessage.Delete False
Next

Leave:
If Not objSession Is Nothing Then objSession.Logoff
Set objSession = Nothing
Set objSelection = Nothing
Set objItem = Nothing
Set objMAPIMessage = Nothing

On Error GoTo 0
Exit Sub

PermanentlyDeleteSelectedMessges_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
PermanentlyDeleteSelectedMessges of Module basExamples"
End Sub

If you want to empty the Deleted items folder, you don't need to use CDO
because if you delete these messages again they're gone forever. This macro
will empty the Deleted Items folder:

Sub EmptyDeletedItemsFolder()
On Error GoTo EmptyDeletedItemsFolder_Error

Dim objItem As Object, objItems As Outlook.Items
Dim objDelItemsFolder As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace
Dim intX As Integer

Set objNS = Application.GetNamespace("MAPI")
Set objDelItemsFolder = objNS.GetDefaultFolder(olFolderDeletedItems)
Set objItems = objDelItemsFolder.Items
For intX = objItems.Count To 1 Step -1
Set objItem = objItems.Item(intX)
'Permanently delete
objItem.Delete
Next

Set objItem = Nothing
Set objItems = Nothing
Set objDelItemsFolder = Nothing
Set objNS = Nothing

On Error GoTo 0
Exit Sub

EmptyDeletedItemsFolder_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
EmptyDeletedItemsFolder of Module basExamples"
End Sub

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Try Picture Attachments Wizard for Outlook! http://tinyurl.com/ckytm
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


"XxLicherxX" wrote:

> Hello everyone,
>
> I am wondering if someone can tell me how I can empty the Deleted Items
> Folder using VBA. I have found a few examples on the web, but none of
> the have worked.
>
> If this is not possible to do, is they a way to permanently delete them
> from the inbox (So the never reach the deleted items folder) ?
>
> Thanks for your help.
>
>

 
Reply With Quote
 
XxLicherxX
Guest
Posts: n/a
 
      11th Jul 2005
Hi Eric,

That was helpful. Thanks for your response.

Dave.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleted items delete permanently! PLEASE HELP!! Sage's Unicorn Windows XP 2 16th Sep 2008 07:41 PM
delete messages permanently from deleted items folder so that it . =?Utf-8?B?UHJhdmlu?= Microsoft Outlook Discussion 2 20th Jun 2007 01:56 PM
how to permanently delete items emptied from deleted items folder =?Utf-8?B?UXVlc3Rpb25pbmc=?= Microsoft Outlook Discussion 5 24th Dec 2006 04:55 AM
Are you sure you want to permanently delete... in the "Deleted Items" folder javaprog Microsoft Outlook Discussion 2 12th Aug 2004 11:37 AM
use vba or vb to permanently delete unopened deleted items bbxrider Microsoft Outlook VBA Programming 1 11th Sep 2003 03:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:54 PM.