+ Reply to Thread
Results 1 to 2 of 2

Moving 30 days and older messages from "Sent Items" to "Deleted Items"

  1. #1
    Registered User
    Join Date
    04-18-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    17

    Post Moving 30 days and older messages from "Sent Items" to "Deleted Items"

    Hello,

    I am using Outlook 2010 with Exchange 2010. I need to move all the "older" messages than 30 days from "Sent Items" to "Deleted Items".
    Can you please let me know how i can achieve the above with VBA script?

    The code below works fine to move messages from "Inbox" older than 30 days to "Old" folder.

    Sub MoveOlderItems()
    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("[email protected]"). _
    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 30 days, adjust as needed.
    If intDateDiff > 30 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 it be modified to achieve what i am trying to do?

    Thank you for your input.

  2. #2
    Forum Contributor
    Join Date
    08-27-2006
    Posts
    136

    Re: Moving 30 days and older messages from "Sent Items" to "Deleted Items"

    The simplest conversion uses olFolderSentMail and olFolderDeletedItems http://msdn.microsoft.com/en-us/libr...ffice.14).aspx

    Please Login or Register  to view this content.
    You could simply delete rather than move.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  2. [SOLVED] Set pivot column items "True" vs. "False"
    By franklin_m in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-06-2012, 07:36 PM
  3. Replies: 2
    Last Post: 01-26-2011, 06:45 AM
  4. Replies: 1
    Last Post: 07-16-2010, 02:44 AM
  5. Replies: 3
    Last Post: 08-27-2009, 07:26 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