Consulting

Results 1 to 3 of 3

Thread: Solved: Full delete

  1. #1
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location

    Solved: Full delete

    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:[vba]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[/vba]

  2. #2
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Any use? I know BA about Outlook!
    http://www.outlookcode.com/codedetail.aspx?id=41
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    I got excited when I read that code, since I had heard I could use CDO to do this to avoid the receipt.. unfortunately I wasn't so lucky, this was still sent:
    Your message
    To: mvidas
    Subject: contains a read receipt!
    Sent: 06/07/2006 8:31 AM
    was deleted without being read on 06/07/2006 8:33 AM.
    The same thing happens when I try emptying deleted items, I had hoped either would work, but I guess not. I'm gonna still keep trying, but I'm marking this as solved since the original question was answered. Thanks!
    Matt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •