Solved

Outlook VBA not all emails moved

Posted on 2014-11-25
1
100 Views
Last Modified: 2014-12-04
Each time I run this code, only some emails are moved.  I have to run it 3 to 5 times to get all of them moved.

 For Each oItem In oFolder.Items
    If TypeName(oItem) = "MailItem" Then
        If Left(oItem.Subject, 31) = "Information about your order (#" And oItem.ReceivedTime > #11/23/2014# Then
            oItem.Move oDestFolder
            Debug.Print oItem.Subject
        End If
    End If
 Next

Open in new window

0
Comment
Question by:rrhandle8
1 Comment
 
LVL 18

Accepted Solution

by:
Simon earned 500 total points
ID: 40465787
Try moving them in reverse order. When you move items out of a collection it stuffs the indexing up.

See code below... just written here, not tested but should work. I do this on a regular basis with Outlook mailitems.

itemCount = oFolder.items.count
 For i from itemcount to 1 step -1
set oItem = ofolder.items(i)
    If TypeName(oItem) = "MailItem" Then
        If Left(oItem.Subject, 31) = "Information about your order (#" And oItem.ReceivedTime > #11/23/2014# Then
            oItem.Move oDestFolder
            Debug.Print oItem.Subject
        End If
    End If
 Next i

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question