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!
  • Students Click Here

*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.

Students Click Here

Getting specific user created folder

Getting specific user created folder

Getting specific user created folder

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:


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)
        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
    ' 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


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


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


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! Already a Member? Login

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