Hemant Sonawane
New Member
- Outlook version
- Outlook 2010 32 bit
- Email Account
- Exchange Server 2010
Hi Diane
I am new to VBA macros, Please help me.
I found macro on this forum that moves the mails which are > 7 days within the oulook folder named as OLD. Can this macro amended to the level where macro can move emails > 90 days to Shared Drive (desktop) folder.
Below is the Macro for your reference
I am new to VBA macros, Please help me.
I found macro on this forum that moves the mails which are > 7 days within the oulook folder named as OLD. Can this macro amended to the level where macro can move emails > 90 days to Shared Drive (desktop) folder.
Below is the Macro for your reference
Code:
Sub MoveAgedMail()
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 your datafile name and each folder in the path
Set objDestFolder = objNamespace.Folders("xyz@domain.com"). _
Folders("Inbox").Folders("Old")
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 90 days, adjust as needed.
If intDateDiff > 45 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