Consulting

Results 1 to 3 of 3

Thread: Copy Files to Public Folder using rules (how do I avoid duplicates?)

  1. #1
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    2
    Location

    Copy Files to Public Folder using rules (how do I avoid duplicates?)

    Hello All,I want outlook to automatically copy e-mails of a project to a public folder for that project. This can be done quite easily using the outlook rules wizard. Now if there are many people working on the project I’d like all them to do the same. The problem arises when group e-mails are sent out, we will end up with many duplicates e-mails in the public folder. I want to find a way round this. The idea I’ve had would be to have a scheduler run a macro weekly to check for duplicates and delete them from the public folder using some VBA similar to the one at the end of this post (uses the body of the e-mail judge if it is a duplicate), then that would require setting up two things for each project, and within a week, on a busy project the public folder could get quite busy. Would it be possible to use VBA to combine the moving of the e-mail to the public folder with a check if that e-mail exists each time the rule is triggered? Perhaps there is a built in thing in the wizard already, any ideas?

  2. #2
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    2
    Location
    Sorry the formatting (carriage returns) doesn't seem to work, posting the code just looks horrible and incomprehensible.

  3. #3
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Quote Originally Posted by bofonomo View Post
    Would it be possible to use VBA to combine the moving of the e-mail to the public folder with a check if that e-mail exists each time the rule is triggered?
    See if something like this works in "Run a script" at the end of the rule.

    Option Explicit

    Sub move_public_mail(itm As mailItem)
    Dim objNS As Namespace
    Dim myPublicFolder As MAPIFolder
    Dim i As Long
    Dim copiedItm As mailItem

    Set objNS = Application.GetNamespace("MAPI")
    Set myPublicFolder = objNS.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("first folder name").Folders("second folder name if any")

    For i = 1 To myPublicFolder.Items.Count
    If itm.Subject = myPublicFolder.Items(i).Subject And itm.SentOn = myPublicFolder.Items(i).SentOn Then
    Debug.Print "Duplicate item."
    GoTo exitRoutine
    End If
    Next

    Set copiedItm = itm.Copy
    copiedItm.Move myPublicFolder

    exitRoutine:
    Set copiedItm = Nothing
    Set myPublicFolder = Nothing
    Set objNS = Nothing

    End Sub

    Sub move_public_mail_test()
    Dim currItem As Object
    Set currItem = ActiveInspector.currentItem
    If TypeOf currItem Is mailItem Then move_public_mail currItem
    Set currItem = Nothing
    End Sub
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

Tags for this Thread

Posting Permissions

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