ADAMC
Well-known Member
- Joined
- Mar 20, 2007
- Messages
- 1,169
- Office Version
- 2013
- Platform
- Windows
Hi all
I found a macro that is perfect for what i need (almost)
It allows me to choose a mailbox then deletes e-mails in the mailbox older than x days (specified in the code)
Only 2 people require this macro my machine runs outlook 2007 macro works
colleagues machine runs outlook 2003 and it does not work and errors out at the line:
Dim oFolder As Folder
Anyone any ideas why or can help me with a macro to delete emals from any mailbox folder x days or older?
Sub DeleteOlderThanxmonths()
Dim oFolder As Folder
Dim Date6months As Date
Dim ItemsOverMonths As Outlook.Items
Dim DateToCheck As String
Date6months = DateAdd("d", -1, 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
P.S I cant use auto archive feature as it seems to be disabled by default within my company.
Thank you!
I found a macro that is perfect for what i need (almost)
It allows me to choose a mailbox then deletes e-mails in the mailbox older than x days (specified in the code)
Only 2 people require this macro my machine runs outlook 2007 macro works
colleagues machine runs outlook 2003 and it does not work and errors out at the line:
Dim oFolder As Folder
Anyone any ideas why or can help me with a macro to delete emals from any mailbox folder x days or older?
Sub DeleteOlderThanxmonths()
Dim oFolder As Folder
Dim Date6months As Date
Dim ItemsOverMonths As Outlook.Items
Dim DateToCheck As String
Date6months = DateAdd("d", -1, 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
P.S I cant use auto archive feature as it seems to be disabled by default within my company.
Thank you!