VBOffice

Directly Enter a Category Name

Before Outlook 2007, you could directly add a category to an item without saving it to the master category list. For Outlook 2007 and up this macro gives you that feature back.

Last modified: 2009/12/15 | Accessed: 46.204  | #80
◀ Previous sample Next sample ▶
SAM SAM
Determine the "identity" of your emails. Set with SAM the sender and the folder folder for sent items with the help of rules.

Before Outlook 2007 you could directly enter a category for any item without saving it to the master category list. Since Outlook 2007 that's not possible anymore.

With the following code you'll get this functionality back. Multiple keywords can be entered separated by a comma or semi-colon.

Copy the code to the module "ThisOutlookSession", and save the project. Then you can create a commandbar button for calling the function by a right click on any toolbar, then choose Customize, Commands, Macros, and drag the name of the function onto a toolbar. By another right-click on the newly created button you can customize its style. (Perform these steps once for the folder view, and if you want to, once for any form for which the function should be available.)

Alternatively, you could also call the function by pressing alt+f8.


tip  How to add macros to Outlook
Public Sub EnterKeyword()
  Dim Coll As VBA.Collection
  Dim obj As Object
  Dim s$

  Set Coll = GetCurrentItems
  If Coll.Count = 0 Then Exit Sub

  s = InputBox("Keyword:")
  s = Trim$(s)
  If Len(s) = 0 Then Exit Sub

  For Each obj In Coll
    obj.Categories = obj.Categories & "," & s
    obj.save
  Next
End Sub

Private Function GetCurrentItems() As VBA.Collection
  Dim Coll As VBA.Collection
  Dim Win As Object
  Dim Sel As Outlook.Selection
  Dim obj As Object
  Dim i&

  Set Coll = New VBA.Collection
  Set Win = Application.ActiveWindow

  If TypeOf Win Is Outlook.Inspector Then
    Coll.Add Win.CurrentItem
  Else
    Set Sel = Win.Selection
    If Not Sel Is Nothing Then
      For i = 1 To Sel.Count
        Coll.Add Sel(i)
      Next
    End If
  End If
  Set GetCurrentItems = Coll
End Function
OLKeeper OLKeeper
OLKeeper reliably prevents users from closing their Outlook window and thus possibly missing reminders or e-mails.
email  Send a message