VBA 在特定时间段内从用户创建的文件夹中删除 Outlook 邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2916078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:40:47 来源:igfitidea点击:
VBA to delete Outlook messages from a user created folder over certain time period
提问by user54729
I'm looking for a VBA code snippet to delete Outlook messages that are six (6) months or older and sit in a user-created folder.
我正在寻找一个 VBA 代码片段来删除六 (6) 个月或更旧并位于用户创建的文件夹中的 Outlook 邮件。
What does that code look like?
这段代码是什么样的?
回答by 76mel
Here is a example script
这是一个示例脚本
Sub DeleteOlderThan6months()
Dim oFolder As Folder
Dim Date6months As Date
Dim ItemsOverMonths As Outlook.Items
Dim DateToCheck As String
Date6months = DateAdd("d", -182, Now())
Date6months = Format(Date6months, "mm/dd/yyyy")
Set oFolder = Application.Session.PickFolder 'or set your folder
DateToCheck = "[Received] <= """ & Date6months & """"
Set ItemsOverMonths = oFolder.Items.Restrict(DateToCheck)
For i = ItemsOverMonths.Count To 1 Step -1
ItemsOverMonths.Item(i).Delete
Next
Set ItemsOverMonths = Nothing
Set oFolder = Nothing
End Sub