StartDownloadsServiceSamplesWorkshopsContact DeutschEnglish
 
Samples
General
Outlook®
 
Awarded by
Microsoft since 2005:
mvp logo
VBOffice Info
Visitors1804787
Impressions6759813
Links
Imprint
Privacy Policy
Contact
Folder: Assign a category to new items
Author: Michael BauerHomepage
Date: 01.02.2007Accessed: 22884
  
Description

With a rule you could assign a category to any new item. But that isn't helpful if you don't know beforehand what to do with the item.

With VBA you're more flexible: For instance, you can assign a category to a new item after it has been moved to a specific folder.

In this example we watch a subfolder of the inbox, and the category name is defined on top in the 'AUTO_CATEGORY' constant.

Private WithEvents Items As Outlook.Items

' Automatically assign this category
' (Diese Kategorie automatisch zuweisen)
Private Const AUTO_CATEGORY As String = "(test)"

Private Sub Application_Startup()
  Dim Ns As Outlook.NameSpace
  Dim Inbox As Outlook.MAPIFolder
  Dim Subfolder As Outlook.MAPIFolder

  Set Ns = Application.GetNamespace("MAPI")

  ' Inbox
  ' (Posteingang)
  Set Inbox = Ns.GetDefaultFolder(olFolderInbox)

  ' Subfolder of the inbox
  ' (Unterordner des Posteingangs)
  Set Subfolder = Inbox.Folders("test")

  Set Items = Subfolder.Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
  Dim Cats() As String
  Dim i&
  Dim Exists As Boolean

  If Len(Item.Categories) Then
    ' Check whether the category is assigned yet
    ' (Pruefe, ob die Kategorie schon zugewiesen ist)
    Cats = Split(Item.Categories, ";")
    For i = 0 To UBound(Cats)
      If LCase$(Cats(i)) = LCase$(AUTO_CATEGORY) Then
        Exists = True
        Exit For
      End If
    Next

    If Exists = False Then
      Item.Categories = Item.Categories & ";" & AUTO_CATEGORY
      Item.Save
    End If

  Else
    Item.Categories = AUTO_CATEGORY
    Item.Save
  End If
End Sub
 
 

ReplyAll alerts you before unintentionally replying all, or if you are a confidential BCC recipient of the ... [more]

 

Access the master category list in the blink of an eye, share your categories in a network, get a reminder service, and ... [more]

 

SAM automatically sets the sender, signature, and folder for sent items, for instance based on the recipient ... [more]

 

OLKeeper reliably prevents users from closing their Outlook window and thus possibly missing reminders or ... [more]