none
Outlook opened by Excel VBA procedure does not show calendar item category colours RRS feed

  • Question

  • I am using MS Office 2007.  I have an Excel VBA procedure that checks if Outlook is open, and if it is not, opens it up:

    Sub OpenOutlook2()

    'Opens Outlook OK, but with no categorisation colours in calendar

        Dim objOL As Outlook.Application
        Dim objNS As Outlook.Namespace
        Dim objInbox As Object
        
        On Error Resume Next
        ' start an Outlook session
        Set objOL = GetObject(, "Outlook.Application")
        If objOL Is Nothing Then
            Set objOL = CreateObject("Outlook.Application")
            Set objNS = objOL.GetNamespace("MAPI")
            Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
            objInbox.Display
            objOL.ActiveWindow.WindowState = olMaximized
        End If
    End Sub

        The procedure works OK and opens Outlook if it is closed.  However, if it was closed and is opened by the procedure, when I then go to Calendar, all the "Categorize" colours for individual items have been removed.  When I click on the "Categorize" button the category names have reverted to the default values ("Blue Category", "Green Category" etc).  The correct categories are still shown by name when the "Events" Current View is selected from the "View" dropdown  menu, but again without colours.

       If I then close down Outlook and re-open it normally via its icon, everything is normal and the colour categories are restored.

       Any help to solve this problem will be much appreciated.

    Monday, January 28, 2013 3:59 PM

All replies

  • I have been unable to find any route to analysing the basic problem, so I have managed to find an alternative way of starting Outlook:

    Sub OpenOutlook3()

        Dim objOL As Outlook.Application
        Dim varStart As Variant
        
        On Error Resume Next
        ' start an Outlook session
        Set objOL = GetObject(, "Outlook.Application")
        If objOL Is Nothing Then
            varStart = Shell("outlook", 4)
            
        End If
        
        On Error GoTo 0
        Set objOL = Nothing
    End Sub

    This works fine, giving a normal start up for Outlook with all the calendar appointment category colours correctly shown.  However, there is one strange feature when the procedure is run using F8 to step through it.  After the line to start Outlook {varStart = Shell("outlook", 4)}  has been executed and Outlook is open, the active application is Outlook, so pressing F8 has no effect until I click in the VBA window again.  When I run it using F5 it runs through seamlessly and completes the whole procedure.  I've no idea why F5 should work when F8 does not.


    • Edited by AndyColRomsey Wednesday, January 30, 2013 11:09 AM typo
    Tuesday, January 29, 2013 5:25 PM