More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

Login

login
password
Remember me

You will need to register and log in if you want to download the source code for the Microsoft Outlook Programming book. The forums and code sharing areas are open to both registered and non-registered visitors.

share code 02-Sep-2010 22:32

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

 

Code level: intermediate    Code area: Outlook Expert Techniques Printer Friendly Version
Title: Get calendar color labels
Description: This VBA sample shows how to use CommandBars to get the complete list of 10 color labels from any calendar folder.
Date: 17-Feb-2005  01:36
Code level: intermediate
Code area: Outlook Expert Techniques
Posted by: Sue Mosher
Body:
All 4comments
Page [ 1  
  17-Feb-2005  09:42   
NOTES:

1) Both this function and the one at http://www.outlookcode.com/codedetail.aspx?id=755 return a semicolon-delimited string of the color labels for a given folder. The GetCalLabelsCB() function returns all the labels, while the GetCalendarLabels() returns only those labels that the user has customized.

2) A practical application of this technique is to get the default set of labels for the current user. This function creates a calendar folder under Deleted Items, returns its labels as a semicolon-delimited list, then deletes that folder:

Function GetDefaultCalLabels()
    Dim objNS As Outlook.NameSpace
    Dim objCal As Outlook.MAPIFolder
    Dim objDeletedItems As Outlook.MAPIFolder
    Dim objMovedFolder As Outlook.MAPIFolder
    On Error Resume Next
        
    Set objNS = Application.GetNamespace("MAPI")
    Set objCal = objNS.GetDefaultFolder(olFolderCalendar)
    GetDefaultCalLabels = GetCalLabelsCB(objCal)
        
    Set objDeletedItems = objNS.GetDefaultFolder(olFolderDeletedItems)
    Set objCal = objDeletedItems.Folders.Add(FormatDateTime(Now, vbGeneralDate), _
                                             olFolderCalendar)
    GetDefaultCalLabels = GetCalLabelsCB(objCal)
    objCal.Delete

    Set objCal2 = Nothing
    Set objCal = Nothing
    Set objNS = Nothing
    Set objMovedFolder = Nothing
    Set objDeletedItems = Nothing
End Function
  17-Feb-2005  09:42   
For more useful CommandBars applications, see http://www.outlookcode.com/d/tips/commandbarfun.htm
  30-Apr-2006  12:31   
In case anyone needs them, here are the RGB values for the label colors:
255, 148, 132
132, 156, 231
165, 222, 99
231, 231, 214
255, 181, 115
132, 239, 247
214, 206, 132
198, 165, 247
165, 206, 198
255, 231, 115
 
  01-May-2006  14:01   
Nice! Thanks, Richard.
Page [ 1  
Post your comment



name        email