Results 1 to 11 of 11

VBA Macro to Move Aged Email Messages To Folder

Threaded View

  1. #1
    Registered User
    Join Date
    12-31-2010
    Location
    Kathleen, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    27

    VBA Macro to Move Aged Email Messages To Folder

    Hi All, if anyone can provide help I would greatly appreciate it. I found some vb online to do exactly what I wanted to do, but I can't get it to work. I'm losing tons of valuable emails due to the companies email retention policy. Currently spending too much time trying to find these emails before they age out and move them to my Mailstore program.

    I pasted this code into a new module and also into ThisOutlookSession and neither works.

    Thanks
    Jason


    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 a subfolder under Inbox
    Set objDestFolder = objSourceFolder.Folders("01_Aged")

    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.ReceivedTime, Now)

    ' I'm using 7 days, adjust as needed.
    If intDateDiff > 300 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
    Attached Images Attached Images

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to move an email from sent folder to another sent folder
    By taylorsm in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 06-06-2017, 12:56 PM
  2. Replies: 6
    Last Post: 11-24-2015, 01:32 PM
  3. look for text in email body and move email to a folder
    By Megatronixs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-10-2015, 05:23 AM
  4. Move an email to a folder in outlook using macro
    By Arunkumark in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 07-11-2013, 09:33 AM
  5. Text box to move messages to a specific folder
    By Interex in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 04-24-2012, 05:39 PM
  6. Outlook 2007 rule to move "marked as complete" messages to a specified folder
    By cybnexcel in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 03-24-2011, 11:28 AM
  7. unable to move email to a folder
    By Ranbir in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 03-03-2010, 08:18 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1