Automatically Move Old Items from a Shared Mailbox to a .PST on a Network Drive

Status
Not open for further replies.

Janika

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Hi there,

I've been looking through a few of the VBA script posts and they seem to be designed to do what I need, but I haven't been able to make them work just by reading and cut/pasting.

Below I have pasted what I came up with after reading through this thread and this other thread. I hit Alt + F11 in Outlook and stuck it under Project 1, but running it gave me a compile error. My trust center macro settings are set to enable all macros. I am testing in Outlook 2013, but the mailbox I need to use this on is in Outlook 2010.

I'm hoping i've missed something obvious!



Code:
Sub MoveAgedMail2()

'Get the function from http://slipstick.me/qf
    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

    Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)

'Use a folder in a different data file
           Set objDestFolder = GetFolderPath("Y:\EverythingBefore_1-4-2015")

    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)

           ' adjust number of days as needed.
            If intDateDiff > 90 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
 
Status
Not open for further replies.
Top