Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-29-2018, 10:19 AM
RetiredCHE RetiredCHE is offline Unexpected Macro Behavior Windows 10 Unexpected Macro Behavior Office 2013
Novice
Unexpected Macro Behavior
 
Join Date: Jun 2016
Location: Alabaster, AL
Posts: 25
RetiredCHE is on a distinguished road
Default Unexpected Macro Behavior

I am running Outlook 2013 in Office 2013 Pro in Windows 10. Everything is fully patched and up to date.



I have written a macro to empty my Trash folder when I quit Outlook. I also put an icon on my QAT to run the macro on demand. The macro runs in both cases, but it only deletes half of the items in the Trash Folder. If I run it a 2nd time on demand it deletes half the remaining items. The macro loops through the items in the folder using a For Each ... Next construct. What am I doing wrong? Below is just the For Each loop of the macro, not the entire macro.

For Each myItem In myTrash
myItem.Delete
Next myItem

Let me know if I need to post the entire macro. Any help will be appreciated!
Reply With Quote
  #2  
Old 03-30-2018, 04:28 AM
gmayor's Avatar
gmayor gmayor is offline Unexpected Macro Behavior Windows 10 Unexpected Macro Behavior Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Run the loop in reverse so as not to screw up the count

Code:
For i = myTrash.Items.Count to 1 step -1
     myTrash.Items(i).Delete
Next i
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 03-30-2018, 05:28 AM
RetiredCHE RetiredCHE is offline Unexpected Macro Behavior Windows 10 Unexpected Macro Behavior Office 2013
Novice
Unexpected Macro Behavior
 
Join Date: Jun 2016
Location: Alabaster, AL
Posts: 25
RetiredCHE is on a distinguished road
Default

Thanks, gmayor! I had to make a minor change to get it to work for me, but you put me on the right track with the reverse loop. Below is the loop with the change I had to make since variable myTrash was already defined as the collection of items in the folder.

For i = myTrash.Count To 1 Step -1
myTrash(i).Delete
Next I

Thanks again! This item is solved.
Reply With Quote
Reply

Tags
2013, macro, trash



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unexpected Macro Behavior Strange macro behavior in 2016 Ulodesk Word VBA 5 04-02-2017 03:34 PM
Unexpected Macro Behavior Unexpected formatting issue kcvinu Word 6 03-29-2017 02:26 PM
Unexpected Macro Behavior unexpected Roman numbering in ToC eNGiNe Word 3 08-09-2016 11:13 PM
Unexpected behavior of actual finish patrickd123 Project 3 07-23-2014 01:53 PM
Unexpected Server Response GreenAccord Project 0 01-31-2006 12:52 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:45 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft