开发者

VBA to delete Outlook messages from a user created folder over certain time period

开发者 https://www.devze.com 2023-01-01 17:29 出处:网络
I\'m looking for a VBA code snippet to delete Outlook messages that are six (6) months or older and sit in a user-creat开发者_开发百科ed folder.

I'm looking for a VBA code snippet to delete Outlook messages that are six (6) months or older and sit in a user-creat开发者_开发百科ed folder.

What does that code look like?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号