Solved

Outlook 2007 Sub Folder Item deletion

Posted on 2012-03-28
3
824 Views
Last Modified: 2012-08-13
I have some code that works well for removing items from top level folders but I cannot figure out how to search down into a sub-folder to remove items.
Can someone please help with an update/append to the code ?

Folders: Root / Hyperion / Essbase Loads

Public Sub RemoveEssbaseUpdates()
     'Deletes messages from example@mail.com that have "Test Mail"
     'in the subject line and are older than the newest message.
    Dim olSession As Outlook.Application, olNamespace As NameSpace
    Dim olInbox As Outlook.MAPIFolder
    Dim olDeleted As Outlook.MAPIFolder
    Dim olSent As Outlook.MAPIFolder
    Dim olFolder As MAPIFolder
    Dim oldeletedFolder As MAPIFolder
    Dim olSentFolder As MAPIFolder
    Dim olItems As Items
    Dim olItems2 As Items
    Dim olItems3 As Items
    Dim i As Integer
 
    Set olSession = New Outlook.Application
    Set olNamespace = olSession.GetNamespace("MAPI")
    Set olInbox = olNamespace.GetDefaultFolder(olFolderInbox)
    Set olDeleted = olNamespace.GetDefaultFolder(olFolderDeletedItems)
    Set olSent = olNamespace.GetDefaultFolder(olFolderSentMail)
    Set olFolder = olInbox.Folders("Essbase Loads")
    'Set oldeletedFolder = olDeleted.Folders("Deleted Items")
    Set olItems = olFolder.Items
    Set olItems2 = olDeleted.Items
    Set olItems3 = olSent.Items
 
   
    If olItems.Count <= 1 Then GoTo Release                 ' don't want to delete anything if there's a single message or no messages in folder
    olItems.Sort ("ReceivedTime")                           ' sort all current items by received time in descending order
    olItems.GetLast
    For i = olItems.Count To 1 Step -1
        If TypeName(olItems.Item(i)) = "MailItem" Then
           
                    olItems.Item(i).Delete
                'End If
            'End If
        End If
    Next
   
   
   
   
Release:
    Set olSession = Nothing
    Set olNamespace = Nothing
    Set olInbox = Nothing
    Set olDeleted = Nothing
    Set olSent = Nothing
    Set olFolder = Nothing
    Set oldeletedFolder = Nothing
    Set olSentFolder = Nothing
    Set olItems = Nothing
    Set olItems2 = Nothing
    Set olItems3 = Nothing
End Sub
0
Comment
Question by:cfranz70
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
Comment Utility
If I understand correctly then:

Root / Hyperion / Essbase Loads

Becomes for example:

olNamespace.GetDefaultFolder(olFolderInbox).folders("Hyperion").folders("Essbase Loads")

Chris
0
 

Author Comment

by:cfranz70
Comment Utility
Thanks Chris, I will try that.  I think you might be right on first glance.  Will circle back asap
0
 

Author Closing Comment

by:cfranz70
Comment Utility
Thanks Chris.  Silly I did not see that but I appreciate your help.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Get an idea of what you should include in an email disclaimer with these Top 5 email disclaimer tips.
Outlook Free & Paid Tools
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now