PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Macro's sporadic performance
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Macro's sporadic performance
![]() |
Macro's sporadic performance |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 colonel.blip@nospambigfoot.com 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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
I'd use a variable to get .Count and get each item and use its Delete
method. See if that helps. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Colonel Blip" <col.blip@nospambigfoot.com> wrote in message news:uPPFs3veEHA.2812@tk2msftngp13.phx.gbl... > 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 > colonel.blip@nospambigfoot.com > 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 > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

