View Single Post
 
Old 05-09-2022, 11:38 PM
Primaxh Primaxh is offline Windows 10 Office 2016
Novice
 
Join Date: May 2022
Posts: 1
Primaxh is on a distinguished road
Unhappy Automatically set Appointment as "private" or private appointments into category

Hello there,

I am not very good at VBA but with the help of google I found a VBA code which should helped me out but doesnt work...

What I want Outlook to do:
If I create a new appointment and set it as "private" I want it to automatically set it as colour-categore named "pirvate" and reversed...

The VBA-code I found was:

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Dim Ns As Outlook.NameSpace

Set Ns = Application.GetNamespace("MAPI")
Set Items = Ns.GetDefaultFolder(olFolderCalendar).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
Dim Appt As Outlook.AppointmentItem
Dim CategoryName as String

CategoryName = "Sample"

If TypeOf Item Is Outlook.AppointmentItem Then
Set Appt = Item
If Appt.Sensitivity = olPrivate Then
If Appt.Categories = "" Then
Appt.Categories = CategoryName
Appt.Save
End If
ElseIf InStr(1, Appt.Categories, CategoryName, vbTextCompare) Then
Appt.Sensitivity = olPrivate
Appt.Save
End If
End If
End Sub



Can someone help me troubleshoot?

Thanks!
Reply With Quote