mvidas
06-06-2006, 06:48 AM
Hi everyone,
Does anyone know how to fully delete a message using vba (like using shift-delete in outlook)? I tried using the .delete method, but that moves it to the Deleted Items folder. I'd rather not iterate through deleted items looking at .receivedtime or .body or anything, if I had the choice).
ADDED: I can't have it iterate through the deleted items, since the item being deleted is a message containing a "read" receipt, and deleting it from deleted items sends a "this was deleted without reading it" message to the sender. If there is a way to shift-delete the message from VBA, it is possible this same auto-response is sent. I'd still like to know though if there is a way to shift-delete it from VBA, and if anyone knows a way to delete a message without this response (even using cdo or anything) I'd be interested in that too.
Is there a method I'm missing? I use Outlook 2000 if it matters.
Thanks!
Matt
ALSO ADDED: For the curious, heres what I'm using so far:Private Sub Application_NewMail()
Dim OlFolder As Variant, OlFolders() As Variant, OlItems As Items
Dim HasReceipt As Boolean, MsgText As String, OlMail As Object
With Application.GetNamespace("MAPI")
OlFolders = Array(.GetDefaultFolder(olFolderInbox), _
.Folders("main mailbox").Folders("subfolder 1").Folders("subfolder 2"))
End With
For Each OlFolder In OlFolders
Set OlItems = OlFolder.Items
For Each OlMail In OlItems
If TypeName(OlMail) = "MailItem" Then
HasReceipt = False
With OlMail
If .UnRead = True Then
If .OriginatorDeliveryReportRequested Then
MsgText = MsgText & IIf(Len(MsgText) = 0, "", vbCrLf) _
& "Delivery report requested: " & OlMail.SenderName _
& " - " & OlMail.Subject
HasReceipt = True
End If
If .ReadReceiptRequested Then
MsgText = MsgText & IIf(Len(MsgText) = 0, "", vbCrLf) _
& "Read receipt requested: " & OlMail.SenderName & _
" - " & OlMail.Subject
HasReceipt = True
End If
If HasReceipt Then
.Copy
.Delete
End If
End If
End With
End If
Next
Next
If Len(MsgText) > 0 Then MsgBox MsgText
End Sub
Does anyone know how to fully delete a message using vba (like using shift-delete in outlook)? I tried using the .delete method, but that moves it to the Deleted Items folder. I'd rather not iterate through deleted items looking at .receivedtime or .body or anything, if I had the choice).
ADDED: I can't have it iterate through the deleted items, since the item being deleted is a message containing a "read" receipt, and deleting it from deleted items sends a "this was deleted without reading it" message to the sender. If there is a way to shift-delete the message from VBA, it is possible this same auto-response is sent. I'd still like to know though if there is a way to shift-delete it from VBA, and if anyone knows a way to delete a message without this response (even using cdo or anything) I'd be interested in that too.
Is there a method I'm missing? I use Outlook 2000 if it matters.
Thanks!
Matt
ALSO ADDED: For the curious, heres what I'm using so far:Private Sub Application_NewMail()
Dim OlFolder As Variant, OlFolders() As Variant, OlItems As Items
Dim HasReceipt As Boolean, MsgText As String, OlMail As Object
With Application.GetNamespace("MAPI")
OlFolders = Array(.GetDefaultFolder(olFolderInbox), _
.Folders("main mailbox").Folders("subfolder 1").Folders("subfolder 2"))
End With
For Each OlFolder In OlFolders
Set OlItems = OlFolder.Items
For Each OlMail In OlItems
If TypeName(OlMail) = "MailItem" Then
HasReceipt = False
With OlMail
If .UnRead = True Then
If .OriginatorDeliveryReportRequested Then
MsgText = MsgText & IIf(Len(MsgText) = 0, "", vbCrLf) _
& "Delivery report requested: " & OlMail.SenderName _
& " - " & OlMail.Subject
HasReceipt = True
End If
If .ReadReceiptRequested Then
MsgText = MsgText & IIf(Len(MsgText) = 0, "", vbCrLf) _
& "Read receipt requested: " & OlMail.SenderName & _
" - " & OlMail.Subject
HasReceipt = True
End If
If HasReceipt Then
.Copy
.Delete
End If
End If
End With
End If
Next
Next
If Len(MsgText) > 0 Then MsgBox MsgText
End Sub