INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Getting specific user created folder

Getting specific user created folder

(OP)
Based on the top script found at https://www.slipstick.com/developer/macro-move-age... (Code will be pasted below, in case that site goes away) I want to modify it so that the objDestFolder points to a folder based on the received date of all emails, assuming the folder exists. So if I received an email Jan 1, 2017, I want to move that mail to \2017\2017-01. If I receive an email on June 1, 2017 and \2017\2017-06 does not exist, the mail is left untouched in my inbox.

What I'm planning on doing is first moving the Set objDestFolder to within the second "If" block, and set the objDestFolder to point to the folder I want, but not quite sure if this is going to refer to (Logically speaking) \Inbox\YYYY\YYYY-MM or \YYYY\YYYY-MM. If the prior, what do I need to do to get the later? How do I test to see if the folder exists prior to the move?

Would I change that line to:

CODE -->

Set objDestFolder = objSourceFolder.Folders(Format(objVariant.SentOn,"\yyyy\yyyy-mm")) 

??

Here is the code from the site:

CODE --> VBA

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("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 7 days, adjust as needed.
            If intDateDiff > 7 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 

-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=
NEVER send the boss to do a techs job

RE: Getting specific user created folder

Hi,

You Set the object variable, objDestFolder, and then test to determine if objDestFolder. Exists...

CODE

If Not objDestFolder Is Nothing Then
   'Houston, we have a folder!
End If 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close