A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Permanent Delete



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old September 14th 06, 06:25 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 10
Default Permanent Delete

Two questions please:

1. I have CDO enabled in Outlook 2000 SR-1, yet the code below fails
saying user defined type not defined highlight the code "
Dim objSession As New MAPI.Session"

2. How can I modify below to select a specific folder (sent items)
instead of active folder.


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

Ads
  #2  
Old September 15th 06, 06:42 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Permanent Delete

Am 14 Sep 2006 09:25:31 -0700 schrieb :

1. For early binding you need to set a reference to CDO 1.21
(Tools/References)

2. The sent items folder you can get with
Application.Session.GetDefaultFolder.

Then you can loop through the folderīs Items collection.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
--
www.VBOffice.net --


Two questions please:

1. I have CDO enabled in Outlook 2000 SR-1, yet the code below fails
saying user defined type not defined highlight the code "
Dim objSession As New MAPI.Session"

2. How can I modify below to select a specific folder (sent items)
instead of active folder.


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

  #3  
Old September 15th 06, 11:28 AM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 10
Default Permanent Delete

Thanks, Re 1, I have done that. Tools/Reference/CDO is checked.

Michael Bauer [MVP - Outlook] wrote:

Am 14 Sep 2006 09:25:31 -0700 schrieb :

1. For early binding you need to set a reference to CDO 1.21
(Tools/References)

2. The sent items folder you can get with
Application.Session.GetDefaultFolder.

Then you can loop through the folderīs Items collection.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
--
www.VBOffice.net --


Two questions please:

1. I have CDO enabled in Outlook 2000 SR-1, yet the code below fails
saying user defined type not defined highlight the code "
Dim objSession As New MAPI.Session"

2. How can I modify below to select a specific folder (sent items)
instead of active folder.


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


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASSIGN PERMANENT CALENDAR BACKGROUND COLORS DUSTYAZ Outlook - Calandaring 5 April 13th 06 10:39 PM
ASSIGN PERMANENT CALENDAR COLORS DUSTYAZ Outlook - Calandaring 0 April 13th 06 06:52 PM
ASSIGN PERMANENT CALENDAR COLORS DUSTYAZ Outlook - Calandaring 0 April 13th 06 06:45 PM
How to insert forced permanent meetings Daniel Outlook - Calandaring 1 April 5th 06 02:54 AM
Delete is permanent?? Angyl Outlook - Using Forms 6 February 8th 06 11:35 PM


All times are GMT +1. The time now is 08:30 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright Đ2004-2025 Outlook Banter.
The comments are property of their posters.