Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-16-2018, 04:06 AM
knarfreppep knarfreppep is offline Looping through emails Windows 10 Looping through emails Office 2016
Novice
Looping through emails
 
Join Date: Mar 2018
Posts: 2
knarfreppep is on a distinguished road
Default Looping through emails

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
Reply With Quote
 



Similar Threads
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
Looping through emails Need help on macro for looping 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:48 PM.


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