C
Colonel Blip
The macro below deletes all of the items that get routed to a junk mail
folder and then deletes (empties) the Delete folder (OL 2003). Most of the
time it works just fine, but sometimes it will not empty the Delete folder.
Instead it may delete one item in the delete folder. Repeated runs will
delete addtional items one at a time.
Anyone see what it is about this code that might contribute to this kind of
behavior?
Thanks.
--
Colonel Blip
(e-mail address removed)
Remove "nospam" when replying.
__________________________________
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 = "Junk E-mail" Then
For lngE = .Folders(lngD).Items.Count To 1 Step -1
.Folders(lngD).Items(lngE).Delete
Next lngE
End If
Next lngD
End With
Next lngC
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 Step -1
.Folders(lngD).Items(lngE).Delete
Next lngE
End If
Next lngD
End With
Next lngC
Set collInfoStores = Nothing
Set olNS = Nothing
End Sub
folder and then deletes (empties) the Delete folder (OL 2003). Most of the
time it works just fine, but sometimes it will not empty the Delete folder.
Instead it may delete one item in the delete folder. Repeated runs will
delete addtional items one at a time.
Anyone see what it is about this code that might contribute to this kind of
behavior?
Thanks.
--
Colonel Blip
(e-mail address removed)
Remove "nospam" when replying.
__________________________________
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 = "Junk E-mail" Then
For lngE = .Folders(lngD).Items.Count To 1 Step -1
.Folders(lngD).Items(lngE).Delete
Next lngE
End If
Next lngD
End With
Next lngC
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 Step -1
.Folders(lngD).Items(lngE).Delete
Next lngE
End If
Next lngD
End With
Next lngC
Set collInfoStores = Nothing
Set olNS = Nothing
End Sub