auto saving email with same subject heading to server directories

not sure exactly what category this should come under but i'll start here. I have a user who gets a lot of email from newsgroups. he saves these to general directories on a win2k3 server. we no longer maintain our exchange/public folders for this so he has to store these on one of our servers so others can search through them. a solution we need is one that can overcome the issue of saving messages that have the same subject heading to directories versus moving them to exchange public folders (which was a lot easier). Outlook seems limited in it's rules language to accomplish this.
demus619Asked:
Who is Participating?
 
David LeeConnect With a Mentor Commented:
Ok, here it is.  This macro can be hooked directly to a rule.  When the rule fires it triggers the macro which saves the message to disk using the subject as the file name.  If a file with that name already exists in the save to folder, then the code will add "(1)" to the file name and attempt to save it again.  If that file name has already been used, then it'll change "(1)" to "(2)" and try again.  It will keep adding one to the number until there is no matching file at which point the message is saved with that name.  There is one hitch to this process.  Saving a message to disk is going to trigger Outlook's built in security, causing a dialog-box to pop up warning that a program is accessing your mailbox and asking for permission to allow it to continue.  There are four ways around this.

1.  Sign the code using a digital certificate.  If you don't have a certificate, then you can use a self-cert.  Here are instructions for doing that: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoxpta/html/odc_dsvba.asp

2.  Use Click-Yes.  This is a small utility that sits in the system tray and clicks the "yes" button for you when Outlook's security pop-up appears.  http://www.contextmagic.com/express-clickyes/

3.  Outlook Redemption.  This is a DLL that safely circumvents Outlook security.  The code would have to be re-written to use Redemption.  http://www.dimastr.com/redemption

4.  Re-write the code to be an Outlook add-in.  Add-ins have different security rules.  THey are also more difficult to write.

Follow these instructions to use the code.

1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor
3.  If not already expanded, expand Modules and click on Module1
4.  Copy the code below and paste it into the right-hand pane of the VB editor window
5.  Edit the code as needed.  I placed comment lines where things need to be changed
6.  Click the diskette icon on the toolbar to save changes
7.  Close the VB Editor
8.  Click Tools->Macro->Security
9.  Set the Security Level to Medium
10.  Create a new rule.
11.  Set the rule to fire on every message
12.  Set the rule's action to "run a script"
13.  Select the macro named Module1.SaveMessageToFileSystem as the target script

Sub SaveMessageToFileSystem(Item As Outlook.MailItem)
    Dim strSaveToPath As String, _
        strFilename As String, _
        intCount As Integer, _
        objFSO As Object
    'Change the path on the following line
    strSaveToPath = "C:\eeTesting\"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    strFilename = Replace(Replace(Item.Subject, ":", ""), "\", "")
    intCount = 1
    Do While True
        If objFSO.FileExists(strSaveToPath & strFilename & ".txt") Then
            strFilename = objFSO.GetBaseName(Item.Subject) & "(" & intCount & ")"
            intCount = intCount + 1
        Else
            Item.SaveAs strSaveToPath & strFilename & ".txt", olTXT
            Exit Do
        End If
    Loop
    Set objFSO = Nothing
End Sub
0
 
David LeeCommented:
Hi demus619,

This would require some VBA code that would check to see if a file with a matching name already exists and, if so, rename it or append a sequence number to it.  I can post code for doing this if this sounds like an option.

Cheers!
0
 
demus619Author Commented:
sure, post it, would be worth viewing and appreciated it.  
0
 
demus619Author Commented:
OK, thanks. i will test this tomorrow at work and assign points then. Opts 1 & 2 look practical for us. I'll get back to  you tomorrow. thanks!
0
 
David LeeCommented:
You're welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.