Consulting

Results 1 to 6 of 6

Thread: Save e-mails automatically when put into folder

  1. #1

    Save e-mails automatically when put into folder

    Hi All,

    I was hoping to find some code that would allow me to drag an e-mail to an Oulook folder named after a job number i.e. B09004 (all job numbers fit this format) and not only will that e-mail be in the outlook folder but it will automatically save that e-mail to a folder of the same name (i.e. B09004) on my server and name it B09004 and a unique number i.e. B09004-1 etc.

    Any help will be greatly appreciated!

    Cheers,

    Mike

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    I've been trying to complete several ideas that I had regarding this request. The one that has the most change to be something usefull is the one of a single watchfolder. Everything you drop in this folder is been archived on a certain condition. The main problem is how to deal with your job numbers.

    I have been able to create some coding that will archive mail based on a certain condition in the subject of the mail. If your customers, suppliers, ... mention your reference, it's probably doable to create something usefull.

    How to get all your jobnumbers in the checking condition. Do we create an array of jobnumbers (based on input from textfile or directory or ????) and then for every jobfolder in the inboxfolder check on the name. If name found, move mail and do stuff you want.

    It's still a work in progess, so be patient.

    Charlize

  3. #3
    Hi Charlize,

    Love your work! Think you might be on to something, I have only really self taught myself on Excel VBA and just getting into Outlook now. I understand the watchfolder but my problem will be only rarely will our customers quote a job number in the subject line and other avenues for getting the save name might need to be explored, in my case anyway.

    My very initial thoughts for looking up a job number against a folder would be to create a list of shortcut folders to the e-mail folder in the actual job number folder but name them the job number rather than e-mail if you follow. This way I can ensure the integrity of the actual job folders in case anything happens and easily manage the job numbers and numbering issues.

    Thank you very much for replying, I am very interested in this so please keep me posted.

    Regards,

    Mike

  4. #4
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    A step by step guide (I hope it's understandable).

    1. Under your inboxfolder you need to create a folder that holds e-mailitems. You call this one Auto-Archive. Exactly as indicated.

    2. Declare some variables public, ie just underneath option explicit and not in a sub or function. You declare them in the ThisOutlookSession module. Press Alt+F11 to go to the vba editor, doubleclick ThisOutlookSession, go to the right side off your screen and press ctrl+home.

    3. insert next piece of coding (underneath option explicit).[vba]'*** check drag item to auto-archive
    Public FolderWatch As Outlook.MAPIFolder
    Public MySubFolderWatch As Outlook.MAPIFolder
    Public WithEvents FolderItems1 As Outlook.Items
    '*** End of check drag item to auto-archive[/vba]

    4. In the private sub Application_Quit() module add the following coding.[vba]Set FolderWatch = Nothing
    Set FolderItems1 = Nothing
    Set MySubFolderWatch = Nothing[/vba]

    5. In the private sub Application_Startup() module add the following coding.[vba]'*** Check new mail in subfolders of inbox - drag auto-archive
    Set FolderWatch = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
    Set MySubFolderWatch = FolderWatch.Folders("Auto-Archive")
    Set FolderItems1 = MySubFolderWatch.Items
    '*** End of check new mail in subfolders inbox[/vba]

    6. Add a new module ie, copy and paste this coding including the private sub and end sub.[vba]Private Sub FolderItems1_ItemAdd(ByVal Item As Object)
    UFProject.Show
    '*** End of check new mail in subfolders inbox
    End Sub[/vba]

    7. Import the next form into outlook. Right click on form and choose the import. You have to unzip the attached file to a directory of your choice and import the form called UFProject.

    8. Close outlook and save the project.

    9. Restart outlook and try dragging an e-mail to auto-archive folder

    Hopefully everything works as expected.

    The coding for saving to disk hasn't been written. You have to change the code in the form button that handles the moving of the e-mail item.

    Charlize

    ps. Your jobnumberfolders are subfolders of the inboxfolder ?

  5. #5
    Thanks Charlize for that, and the step by step guide! I have got it working to the point of the form loading and it allowing me to choose an inbox subfolder to which to archive the e-mail.

    Now after seeing what you have done I have had an idea, rather than have hundreds of inbox subfolders for job numbers, is there anyway after dragging the e-mail to the Auto-Archive folder that the form asks you for a 6 character job number and then when you hit archive will search folders within a certain folder i.e C:\Example\.....and save it within the folder matching the job number you specified, and for the piece de resistance, save the e-mail as the job number you specified.

    I cannot tell you how much I am appreciating your help on this!

  6. #6
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Attached the modified form where you can type something to narrow down the selection. If no match is found, the command button to archive changes his label to Add Jobfolder. The new folder will use the value that you have typed in the textbox. This form replaces the previous one. Best to delete the earlier one and import the new one.

    Hope you like it.

    Charlize

Posting Permissions

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