Consulting

Results 1 to 2 of 2

Thread: Help with deleting items If/Then

  1. #1
    VBAX Newbie
    Joined
    May 2018
    Posts
    1
    Location

    Help with deleting items If/Then

    Hi all-

    I have a script that forwards message with some information and then deletes the message. It works, except that I don't want it to delete messages if the message is currently in the deleted items folder. I can't seem to make this work. How do I write the statement "If message is in deleted items, then do not delete. Else, delete"?

    Alternately, is there an easy way to get the email header info so that can be forwarded along as well? The reason for leaving the email in deleted items is so that we can remote to the user and check out the header info if we need to.

    Any help is much appreciated!!!

    Thanks!

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Normally your code would be included but this should be adaptable to whatever you have.

    Public Sub LeaveInDefaultDeletedItemsFolder()
    
        Dim objItem As mailItem
        
        Set objItem = ActiveExplorer.Selection.item(1)
        
        If objItem.Parent <> Session.GetDefaultFolder(olFolderDeletedItems) Then
            MsgBox "The folder is: " & objItem.Parent & vbCr & vbCr & "Put code to delete here."
        Else
            MsgBox "The folder is: " & objItem.Parent & vbCr & vbCr & "Do not delete."
        End If
        
    End Sub
    
    
    Public Sub LeaveInAnyFolderName()
    
        Dim objItem As mailItem
      
        Set objItem = ActiveExplorer.Selection.item(1)
     
        Debug.Print objItem.Parent
        
        If objItem.Parent <> "Deleted Items" Then
            MsgBox "The folder is: " & objItem.Parent & vbCr & vbCr & "Put code to delete here."
        Else
            MsgBox "The folder is: " & objItem.Parent & vbCr & vbCr & "Do not delete."
        End If
        
    End Sub
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

Posting Permissions

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