B
batesharold
I have been using the following script posted earlier on this forum and
it works fine, I tried to be clever by executing it on This Outlook
Session Quit (why doesn't it have a before close event?) and it gives
an internal error. I would be grateful if someone could tell me what I
should be doing. I am using Outlook 2003
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
it works fine, I tried to be clever by executing it on This Outlook
Session Quit (why doesn't it have a before close event?) and it gives
an internal error. I would be grateful if someone could tell me what I
should be doing. I am using Outlook 2003
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