Solved

VBA code for outlook which checks for the categories of the emails and then saves them to file folders (same names with categories) on the drive if there is an attachment

Posted on 2010-08-30
3
356 Views
Last Modified: 2012-05-10
I need a vba code for MS Outlook which checks if there is a new email which is categorized with outlook categories (not necessarily all the categories, user should be able to specify which categories to check). Then it checks if the emails have attachments and if there is , the code saves the attachment to a file folder which has the same name as the category (If the file folder does not exist, the folder should be created).

Obviously, some emails might have several categories. I dont know what to do in those cases. We might try to save the attachments to each categories file folder. Or something else. I am open to suggestions on that issue.
0
Comment
Question by:awesomejohn19
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 33570225
Hi, awesomejohn19.

Is the user going to set the categories once or are they going to be changing them a lot?
0
 

Author Comment

by:awesomejohn19
ID: 33576475
Hi BluedDevilFan,

They'll probably have a standard set of categories, but from time to time, they are likely to add new ones each month. So, they will change it.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 33599408
Here is the code for doing this.  Follow these instructions to use it.

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects
4.  If not already expanded, expand Modules
5.  Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
6.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
7.  Edit the code as needed.  I included comments wherever something needs to or can change
8.  Click the diskette icon on the toolbar to save the changes
9.  Close the VB Editor
10. Create a rule that fires for these messages
11. Set the rule's action to "run a script" and select this script as the one to run
Sub SaveAttachmentToCategoryFolder(Item As Outlook.MailItem)
    'On the next line change the path to the root folder that the categorical folders appear under'
    Const ROOT_PATH = "C:\eeTesting\"
    Dim arrCats As Variant, varCat As Variant, olkAttachment As Outlook.Attachment
    If Item.Attachments.count > 0 Then
        If Len(Item.Categories) > 0 Then
            arrCats = Split(Item.Categories, ",")
            For Each varCat In arrCats
                Select Case varCat
                    'On the next line change the category names.  These are the categories that trigger saving attachments.'
                    Case "Cat1", "Cat2", "Cat3"
                        For Each olkAttachment In Item.Attachments
                            olkAttachment.SaveAsFile ROOT_PATH & varCat & "\" & olkAttachment.FileName
                        Next
                End Select
            Next
        End If
    End If
    Set olkAttachment = Nothing
End Sub

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question