![]() |
|
#1
|
|||
|
|||
![]()
Hi all!
Code below loops through every email in Inbox and is supposed to move those pre-processed so as to have {P} at the beginning of their Subject to an Archived folder under Inbox. Problem is, not all such emails are archived in a 'run' ... one may need to run the code two or three times to move all emails. I'd hoped DoEvents would help ... it didn't. I realise I can just loop through the code (' For bytLoop = 1 to 5) but does anyone know why the code might be failing or a better way please? Code:
Set appApplication = CreateObject("Outlook.Application") Set nspNameSpace = appApplication.GetNamespace("MAPI") Set objFolder_Source = nspNameSpace.GetDefaultFolder(olFolderInbox) Set objFolder_Archived = objFolder_Source.Folders.Add("Archived") Set objFolder_Archived = objFolder_Source.Folders("Archived") Set objFolder_OldItems = objFolder_Source.Folders.Add("Old Items") Set objFolder_OldItems = objFolder_Source.Folders("Old Items") ' For bytLoop = 1 to 5 For Each varMailItem In objFolder_Source.Items If Left(varMailItem.Subject, 3) = "{P}" Then varMailItem.Move objFolder_Archived DoEvents End If ' Next Next varMailItem |
#2
|
|||
|
|||
![]()
I had a similar issue with a macro to delete all items in my Trash folder. The solution was to loop in reverse from the count of items to 1. Using that approach the macro worked the first time. I hope this will work for you.
RetiredCHe |
#3
|
|||
|
|||
![]()
Looping through my code x5 solved my problem, with execution time still excellent.
But I'll try/use your solution as I prefer it to my 'scatter gun' approach. Thanks for taking an interest Alan! |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Looping presentation | elico | PowerPoint | 2 | 02-25-2016 05:58 AM |
Looping several slides | gabby | PowerPoint | 11 | 04-25-2015 03:05 AM |
![]() |
kilosub | Word VBA | 31 | 07-27-2011 01:37 PM |
Looping video | tomasball | PowerPoint | 0 | 10-30-2010 02:38 PM |
Unbreakable looping | Dixon | Outlook | 0 | 09-23-2009 02:10 PM |