PDA

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



bofonomo
11-20-2013, 02:48 AM
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?

bofonomo
11-20-2013, 02:50 AM
Sorry the formatting (carriage returns) doesn't seem to work, posting the code just looks horrible and incomprehensible.

skatonni
11-21-2013, 04:41 PM
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