Consulting

Results 1 to 5 of 5

Thread: Trigger Macro on Category Change/Add

  1. #1

    Trigger Macro on Category Change/Add

    Hi all,

    I'm pretty experienced writing macros using VBA for Excel, but I'm new to writing them for Outlook. I have a few categoried prepared that I use to organize my tasks/emails in Outlook. If I assign one of those categories to an email message, I want a macro to trigger that saves that file to a folder that I designate immediately (I don't want to have to run something periodically). Is this something that can be done?

    Thanks in advance!

  2. #2
    you can do it in the itemsend event, but i do not know that there is any automation on selecting a category, unless the propertychange event of the mailitem is fired

  3. #3
    I was actually able to come up with something, it's not perfect though. The code works, but for some reason only once. It changes the category from "Add to Folder" to "Added to Folder", but I can't get it to save:

    Private WithEvents Items As Outlook.Items
    Private Sub Application_Startup()
        Dim Ns As Outlook.NameSpace
        
        Set Ns = Application.GetNamespace("MAPI")
        Set Items = Ns.GetDefaultFolder(olFolderInbox).Items
    End Sub
    Private Sub Items_ItemChange(ByVal Item As Object)
        On Error Resume Next
        Dim email As Outlook.MailItem
        
        If TypeOf Item Is Outlook.MailItem And Item.Categories = "Add to Folder" Then
            Set email = Item
            email.Categories = ""
            email.Categories = "Added to Folder"
            email.SaveAs "C:\Users\thomas.oconnell\Desktop\Test\" & email.Subject, olMSG
        End If
        
    End Sub
    Last edited by JumblyBug; 04-17-2014 at 08:08 AM.

  4. #4
    , but I can't get it to save:
    what happens? error? wrong result nothing?

    probably you should save the email first
    then in saveAs you should supply the correct file extension to match the specified file type, like
    email.save
    email.SaveAs "C:\Users\thomas.oconnell\Desktop\Test\" & email.Subject & ".msg", olMSG

  5. #5
    Quote Originally Posted by westconn1 View Post
    what happens? error? wrong result nothing?

    probably you should save the email first
    then in saveAs you should supply the correct file extension to match the specified file type, like
    email.save
    email.SaveAs "C:\Users\thomas.oconnell\Desktop\Test\" & email.Subject & ".msg", olMSG
    This worked great, thanks for your help!

Posting Permissions

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