VBA update outlook calendar category

omnivl

Board Regular
Joined
Aug 25, 2014
Messages
53
Hi

I have the following code that works well but i cannot seem to get the category color to work
any ideas?

Code:
Option Explicit



Sub AddToOutlook()

    Dim OL As Outlook.Application
    Dim olAppt As Outlook.AppointmentItem
    Dim NS As Outlook.Namespace
    Dim colItems As Outlook.Items
    Dim olApptSearch As Outlook.AppointmentItem
    Dim r As Long, sSubject As String, sBody As String
    Dim dStartTime As Date, dDuration As Double
    Dim sSearch As String, bOLOpen As Boolean

    On Error Resume Next
    Set OL = GetObject(, "Outlook.Application")
    bOLOpen = True
    If OL Is Nothing Then
        Set OL = CreateObject("Outlook.Application")
        bOLOpen = False
    End If
    Set NS = OL.GetNamespace("MAPI")
    Set colItems = NS.GetDefaultFolder(olFolderCalendar).Items

    For r = 2 To 500

        If Len(Sheets("ProcurementContracts").Cells(r, 11).Value) = 0 Then GoTo NextRow
        sSubject = Sheets("ProcurementContracts").Cells(r, 2).Value & " - " & Sheets("ProcurementContracts").Cells(r, 3).Value
        sBody = Sheets("ProcurementContracts").Cells(r, 13).Value
        dStartTime = Sheets("ProcurementContracts").Cells(r, 11).Value
        dDuration = 30

        sSearch = "[Subject] = " & sQuote(sSubject)
        'sSearch = "[Body] = Account " & sQuote(sBody)
        Set olApptSearch = colItems.Find(sSearch)

        If olApptSearch Is Nothing Then
            Set olAppt = OL.CreateItem(olAppointmentItem)
            olAppt.Body = "Account " & sBody
            olAppt.Subject = "Procurement - " & sSubject
            'olAppt.Subject = sSubject
            olAppt.Start = dStartTime
            olAppt.Duration = dDuration
            olAppt.Categories = "Red"
            olAppt.Close olSave
        End If

NextRow:
    Next r

    If bOLOpen = False Then OL.Quit

End Sub

Function sQuote(sTextToQuote)
    sQuote = Chr(34) & "Procurement - " & sTextToQuote & Chr(34)
End Function
 

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top