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?
One suggestion I've tried is following:
replacing these lines
For lngE = .Folders(lngD).Items.Count To 1 Step -1
.Folders(lngD).Items(lngE).Delete
Next lngE
with this
With .Folders(lngD)
do while .items.Count > 0
.items(1).delete
Loop
End with
This works as well only now I often have to run the macro twice to empty the
delete folder. The first time nothing happens; the second time it works
fine.
--
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?
One suggestion I've tried is following:
replacing these lines
For lngE = .Folders(lngD).Items.Count To 1 Step -1
.Folders(lngD).Items(lngE).Delete
Next lngE
with this
With .Folders(lngD)
do while .items.Count > 0
.items(1).delete
Loop
End with
This works as well only now I often have to run the macro twice to empty the
delete folder. The first time nothing happens; the second time it works
fine.
--
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