Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I followed the below example:

https://www.slipstick.com/developer/create-a-new-message-using-vba/

I want to categorize mail automatically when I send an email by macro. but, sometimes category is in category.

For example, suppose, "Report" Category is under "Company" Category.

How can i assign my sent mail to "Report" Category in "Company" Category? Here is my code. it is almost same with the example code.

Public Sub CreateNewMessage()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
With objMsg
  .To = "Alias@domain.com"
  .CC= "Alias2@domain.com"
  .BCC = "Alias3@domain.com"
  .Subject = "This is the subject"
  .Categories = "Test"
  .VotingOptions = "Yes;No;Maybe;"
  .BodyFormat = olFormatPlain ' send plain text message
  .Importance = olImportanceHigh
  .Sensitivity = olConfidential
  .Attachments.Add ("path-to-file.docx")
 ' Calculate a date using DateAdd or enter an explicit date
  .ExpiryTime = DateAdd("m", 6, Now) '6 months from now
  .DeferredDeliveryTime = #8/1/2012 6:00:00 PM#
  .Display
End With
                Hello and welcome to StackOverflow, could you please clarify what you mean when saying "category is in category" ?
– Pierre Chevallier
                Dec 13, 2017 at 11:34

Categories in Outlook is a flat list, a category cannot be a child (or a parent) of another category. That being said, you can assign multiple categories to any item - just separate them with ";"

.Categories = "Test;Report;Some Other Category"
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.