Douglas Littlefield
Member
- Outlook version
- Outlook 2010 64 bit
- Email Account
- Exchange Server
I'm using Outlook 2010 on an exchange server.
What i'm trying to do is create a macro that will search my inbox for anything that is older than 60 days and move it to my 7 Year retention folder under Managed Folders
I can easily do this within my inbox: Example:
search inbox 60 days move to @test folder as a sub folder in the inbox....
Can someone please help me figure out how to get it to move from the inbox to the 7 year retention folder
What i'm trying to do is create a macro that will search my inbox for anything that is older than 60 days and move it to my 7 Year retention folder under Managed Folders
I can easily do this within my inbox: Example:
search inbox 60 days move to @test folder as a sub folder in the inbox....
Code:
Private Sub Application_Startup()
Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim objVariant As Variant
Dim lngMovedItems As Long
Dim intCount As Integer
Dim intDateDiff As Integer
Dim strDestFolder As String
Set objOutlook = Application
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)
' use a subfolder under Inbox
Set objDestFolder = objSourceFolder.Folders("@test")
For intCount = objSourceFolder.Items.Count To 1 Step -1
Set objVariant = objSourceFolder.Items.Item(intCount)
DoEvents
If objVariant.Class = olMail Then
intDateDiff = DateDiff("d", objVariant.SentOn, Now)
' I'm using 7 days, adjust as needed.
If intDateDiff > 60 Then
objVariant.Move objDestFolder
'count the # of items moved
lngMovedItems = lngMovedItems + 1
End If
End If
Next
' Display the number of items that were moved.
MsgBox "Moved " & lngMovedItems & " messages(s)."
Set objDestFolder = Nothing
End Sub
Can someone please help me figure out how to get it to move from the inbox to the 7 year retention folder