ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 331|回复: 0

[求助] 如何去重.pst文件重复邮件

[复制链接]

TA的精华主题

TA的得分主题

发表于 2023-11-8 16:01 | 显示全部楼层 |阅读模式
如主题,背景介绍:一个公共邮箱用来分发产生的数据邮件,每天400封左右。公邮内存99G,实际运行过程快满内存,邮箱自动删除邮件。
现:IT已恢复既往2023.1-9月自动删除的文件,但PST多达34个,也就是说实际这个邮箱大概发送了100G左右邮件,但备份有324G左右。

需求:
1、如何将这34个pst里边邮件跑一遍,去重,删除多余邮件或内存?
2、最终得到唯一的邮件,再合并PST,希望得到12个左右PST,每个10Gb左右。

我搜了一下网络上的VBA代码,但是VBA代码在outlook客户端运行显示编译错误,跑不起来。


Sub RemoveDuplicates()
    Dim objFolder As Folder
    Dim objMail As MailItem
    Dim objNewMail As MailItem
    Dim arrMails() As Variant
    Dim i As Long, j As Long
    Dim bExists As Boolean
    Dim strPstPath As String
   
    ' Set the path to the PST file
    strPstPath = D:\old\Exchange.pst' Replace with the actual path to your PST file
   
    ' Loop through each PST file
    For Each objFolder In Application.Session.Folders
        If objFolder.Name Like "*.pst" Then
            ' Read mails from the current PST file
            arrMails = objFolder.Items.Restrict("[Received] >= '" & DateAdd("m", -12, Date) & "'").Sort("[Received] DESC" & vbCrLf & "Ascending:=False") ' Modified line here
            ReDim Preserve arrMails(1 To UBound(arrMails))
            
            ' Loop through each mail in the current PST file
            For i = 1 To UBound(arrMails)
                Set objMail = arrMails(i)
                bExists = False
               
                ' Check if the mail has already been processed (exists in the array)
                For j = 1 To UBound(arrMails)
                    If arrMails(j).Subject = objMail.Subject And arrMails(j).ReceivedTime = objMail.ReceivedTime Then
                        bExists = True
                        Exit For
                    End If
                Next j
               
                ' If the mail is not processed, add it to the array and set bExists to True
                If Not bExists Then
                    Set objNewMail = objMail.Copy
                    arrMails(UBound(arrMails) + 1) = objNewMail
                End If
            Next i
        End If
    Next objFolder
End Sub


以上,求助各位大佬,请指正。

如何去重

如何去重

显示编译错误

显示编译错误
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-6-2 22:39 , Processed in 0.027903 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表