本文介绍了宏在Outlook中删除重复emails-的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Public Sub RemDups()

Dim t As Items, _
    i As Integer, _
    arr As Collection, _
    f As Folder, _
    parent As Folder, _
    target As Folder, _
    miLast As MailItem, _
    mi As MailItem

Set parent = Application.GetNamespace("MAPI").PickFolder
Set target = Application.GetNamespace("MAPI").PickFolder


For Each f In parent.Folders
    Set t = f.Items
    t.Sort "[Subject]"
    i = 1
    Set miLast = t(i)
    Set arr = New Collection
    While i < t.Count
        i = i + 1
        If TypeName(t(i)) = "MailItem" Then
            Set mi = t(i)
            If miLast.Subject = mi.Subject And miLast.Body = mi.Body _
            And miLast.ReceivedTime = mi.ReceivedTime Then
                arr.Add mi
            Else
                Set miLast = mi
            End If
        End If
    Wend
    For Each mi In arr
        mi.Move target
    Next mi
Next f

End Sub

设置miLast = T(I)给出运行时error'440数组索引越界
请帮助

推荐答案

这是修改后的版本创建于网(<一个href=\"https://excelandaccess.word$p$pss.com/2013/06/24/delete-duplicate-emails-via-ms-excel-vba/#comment-1493\"相对=nofollow称号=删除重复项通过MS Excel的VBA电子邮件>博客ExcelandAccess )

This is a modified version founded in the web (Blog ExcelandAccess)

这code让选择一个文件夹进行搜索并删除重复项。

This code let pick a folder to search and delete duplicate items.

Option Explicit

'Set a reference to the Microsoft Scripting Runtime from Tools, References.

Sub DeleteDuplicateEmailsInSelectedFolder()

Dim i As Long
Dim n As Long
Dim Message As String
Dim Items As Object
Dim AppOL As Object
Dim NS As Object
Dim Folder As Object

Set Items = CreateObject("Scripting.Dictionary")

'Initialize and instance of Outlook
Set AppOL = CreateObject("Outlook.Application")

'Get the MAPI Name Space
Set NS = AppOL.GetNamespace("MAPI")

'Allow the user to select a folder in Outlook
Set Folder = NS.PickFolder

'Get the count of the number of emails in the folder
n = Folder.Items.Count

'Check each email starting from the last and working backwards to 1
'Loop backwards to ensure that the deleting of the emails does not interfere with subsequent items in the loop
For i = n To 1 Step -1

    On Error Resume Next
    'Load the matching criteria to a variable
    'This is setup to use the Sunject and Body, additional criteria could be added if desired
    Message = Folder.Items(i).Subject & "|" & Folder.Items(i).Body

        'Check a dictionary variable for a match
        If Items.Exists(Message) = True Then
        'If the item has previously been added then delete this duplicate
        Folder.Items(i).Delete
    Else
        'In the item has not been added then add it now so subsequent matches will be deleted
        Items.Add Message, True
End If

Next i

ExitSub:

'Release the object variables from memory
Set Folder = Nothing
Set NS = Nothing
Set AppOL = Nothing

End Sub

一个更好的版本是找到在其他文件夹重复的电子邮件在递归模式。

A better version is to find duplicate e-mails in other folder in recursive mode.

这篇关于宏在Outlook中删除重复emails-的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 02:14