Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Kingwood, Texas, USA
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Empty all Delete Folders in Outlook (vba/outlook 2003)

    I have several personal folders in addition to my main outlook folder. These
    have a tendency to accumulate messages, notes, etc. that have been deleted
    and, when I think of it, I go thru each of the pst folders, find the delete
    folder and empty it.

    I would like to have a macro that would go thru each of the delete folders
    and empty them.

    Is there code that will do such a thing?

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Empty all Delete Folders in Outlook (vba/outlook 2003)

    <P ID="edit" class=small>(Edited by JohnBF on 28-Apr-04 17:34. )</P>So you have multiple PSTs, correct? Do you have multiple nested delete folders, or just one per PST?

    Here's some rough code to list the information stores, you can modify it to loop through and operate on your PSTs :

    Sub EnumInfoStores()
    Dim olNS As Outlook.NameSpace
    Dim collInfoStores As Outlook.Folders
    Dim lngC As Long

    Set olNS = Application.GetNamespace("MAPI")
    Set collInfoStores = olNS.Folders

    For lngC = 1 To collInfoStores.Count
    Debug.Print collInfoStores(lngC).Name
    Next lngC
    End Sub

    Edited from here down:
    If you have only one Deleted Items Folder per PST, you should be able to get at it though something like (untested):

    Dim lngD As Long, lngE As Long
    For lngD = 1 To .Folders.Count
    ' can't find a class or folder type for Del Items Foldrs - ??
    If .Folders(lngD).Name = "Deleted Items" Then
    If CBool(.Folders(lngD).Items.Count) Then
    For lngE = .Folders(lngD).Items.Count To 1
    .Folders(lngD).Items(lngE).Delete
    Next lngE
    End If
    End If
    Next lngD

    Post back if you need more help.
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Kingwood, Texas, USA
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Empty all Delete Folders in Outlook (vba/outlook 2003)

    Thanks.

    Ok, here is where my ignorance becomes obvious!!

    First, you are correct - there is only one "Deleted Items" folder for each pst.

    The first code listing works fine to return the names of my three pst's I am using for testing.
    The second code listing gives an error (no doubt because I am not familiar with coding enough to understand the vernacular OR more likely because I am using the code incorrectly).

    First question - is the code listing you edited stand alone, i.e. should work within sub or does it need the upper code to work?
    In either case, when I debug and it hits "For lngD = 1 To .Folders.Count" I get an error on the .Folders that it is an invalid or unqualified reference.

    >> Post back if you need more help.
    Definitely.

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Empty all Delete Folders in Outlook (vba/outlook 2003)

    With no nested Deleted Items Folders, it should all come together like this:

    Sub ClearAllDeletedItems()
    Dim olNS As Outlook.NameSpace
    Dim collInfoStores As Outlook.Folders
    Dim lngC As Long, lngD As Long, lngE As Long

    Set olNS = Application.GetNamespace("MAPI")
    Set collInfoStores = olNS.Folders

    For lngC = 1 To collInfoStores.Count
    With collInfoStores(lngC)
    For lngD = 1 To .Folders.Count
    If CBool(.Folders(lngD).Items.Count) And _
    .Folders(lngD).Name = "Deleted Items" Then
    For lngE = .Folders(lngD).Items.Count To 1
    .Folders(lngD).Items(lngE).Delete
    Next lngE
    End If
    Next lngD
    End With
    Next lngC

    Set collInfoStores = Nothing
    Set olNS = Nothing
    End Sub
    -John ... I float in liquid gardens
    UTC -7ąDS

  5. #5
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Kingwood, Texas, USA
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Empty all Delete Folders in Outlook (vba/outlook 2003)

    John,

    This seems to loop thru just fine but it accomplishes no change on the items in any of the folders.

    I put some debug prints in and it is indeed cycling thru the pst's and folders. However, watching the code when it gets to:

    If CBool(.Folders(lngD).Items.Count) And _
    .Folders(lngD).Name = "Deleted Items" Then
    For lngE = .Folders(lngD).Items.Count To 1
    .Folders(lngD).Items(lngE).Delete

    it goes thru the line ending with .Count To 1 but the next action is to jump to the next End If and not fire on the .Folders(lngD).Items(lngE).Delete statement. This continues right on down the list of folders and pst's.

  6. #6
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Empty all Delete Folders in Outlook (vba/outlook 2003)

    Oh no! I made a stupid omission! See if this change to the appropriate line works:

    For lngE = .Folders(lngD).Items.Count To 1 Step -1

    ... and please accept my apologies. <img src=/S/stupidme.gif border=0 alt=stupidme width=30 height=30>
    -John ... I float in liquid gardens
    UTC -7ąDS

  7. #7
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Kingwood, Texas, USA
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Empty all Delete Folders in Outlook (vba/outlook 2003)

    >> ... and please accept my apologies.

    Are you kidding!?!
    You graciously wrote the code and shared it AND helped debug it.
    It is I who should apologize for being so lame in this stuff.

    Worked like a charm. Thanks a bunch.

Posting Permissions

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