An Outlook user asked:
I'm using Insights feature of Outlook and my Office 365 mailbox. I like the idea of automatically generating activities/appointments for 'Focus Time' and 'Meeting preparations' but would like assign a category to the Focus Time appointments and change the Show time as state to 'Tentative' rather than 'Busy'.
.
Although you can't change this through the Insights feature, you can use a macro to update the events in your calendar. While its easy enough to run once a week after Insights generates the events, you could use a reminder to run it automatically.
If you are going to run the macro manually, put the macro in a new module and add a button for it to the ribbon or quick access toolbar. If you want ot automate it, you'll put it in ThisOutlookSession.
In this macro, I add the category "Focus Time", remove the reminder, and set the busy status to Tentative
Option Explicit Public Sub ChangeInsights() Dim calFolder As folder Dim CalItems As Outlook.Items Dim ResItems As Outlook.Items Dim sFilter As String Dim Appt As AppointmentItem 'Object Set calFolder = Session.GetDefaultFolder(olFolderCalendar) Set CalItems = calFolder.Items ' Sort all of the appointments based on the start time CalItems.Sort "[Start]" On Error Resume Next sFilter = "[Subject] = Focus Time" Set ResItems = CalItems.Restrict(sFilter) 'Loop through the items in the collection. For Each Appt In ResItems With Appt .Categories = "Focus time" .ReminderSet = False .BusyStatus = olTentative .Save End With Next Set Appt = Nothing End Sub
Change the Focus Time automatically
Use this macro to change the focus time events as they are added to the Calendar.
This macro goes in ThisOutlookSession.
Dim CalFolder As Outlook.folder Public WithEvents CalItems As Outlook.Items Sub Application_Startup() Set calFolder = Session.GetDefaultFolder(olFolderCalendar) Set CalItems = calFolder.Items End Sub Private Sub CalItems_ItemAdd(ByVal Item As Object) If Item.Class = olAppointment Then If InStr(Item.Subject, "Focus time") > 0 Then With Item .Categories = "Focus time" .ReminderSet = False .BusyStatus = olTentative .Save End With End Sub
Remove older Focus Time appointments
If you want to remove older Focus Time appointments to tidy up your calendar. this code to delete Focus Time appointments more than 14 days in the past.
Sub CleanUpFocusTime() Dim calFolder As folder Dim CalItems As Outlook.Items Dim ResItems As Outlook.Items Dim sFilter As String Dim Appt As AppointmentItem 'Object Dim intCount 'As Integer Dim i As Integer Set calFolder = Session.GetDefaultFolder(olFolderCalendar) Set CalItems = calFolder.Items 'Sort all of the appointments based on the start time CalItems.Sort "[Start]" On Error Resume Next sFilter = "[Subject] = " & Chr(34) & "Focus time" & Chr(34) & " AND [Start] < '" & Date - 14 & "'" Debug.Print sFilter Set ResItems = CalItems.Restrict(sFilter) Debug.Print ResItems.count For intCount = ResItems.count To 1 Step -1 ResItems(intCount).Delete Debug.Print intCount Next End Sub
Delete older Focused items automatically
To automatically delete older Focus Time events, you can edit the ApplicationStartup macro. When you restart Outlook on a Friday, the delete macro (above) runs. To run it on another day of the week, change the day name in the macro.
If you prefer to run it every time you restart Outlook, remove the If and End If lines so that it calls the CleanUpFocusTime every time Outlook is restarted.
Sub Application_Startup() Set calFolder = Session.GetDefaultFolder(olFolderCalendar) Set CalItems = calFolder.Items ' delete older focused events datefri = WeekdayName(Weekday(Date)) If datefri = "Friday" Then CleanUpFocusTime End If End Sub
How to use the macros on this page
First: You need to have macro security set to the lowest setting, Enable all macros during testing. The macros will not work with the top two options that disable all macros or unsigned macros. You could choose the option Notification for all macros, then accept it each time you restart Outlook, however, because it's somewhat hard to sneak macros into Outlook (unlike in Word and Excel), allowing all macros is safe, especially during the testing phase. You can sign the macro when it is finished and change the macro security to notify.
To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, look at Tools, Macro Security.
After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
Macros that run when Outlook starts or automatically need to be in ThisOutlookSession, all other macros should be put in a module, but most will also work if placed in ThisOutlookSession. (It's generally recommended to keep only the automatic macros in ThisOutlookSession and use modules for all other macros.) The instructions are below.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
To put the macro code in ThisOutlookSession:
- Expand Project1 and double click on ThisOutlookSession.
- Copy then paste the macro into ThisOutlookSession. (Click within the code, Select All using Ctrl+A, Ctrl+C to copy, Ctrl+V to paste.)
More information as well as screenshots are at How to use the VBA Editor
I added the first block of code to a module so I could run it manually, however it doesn't work outside of running in it VBA. I made a minor edit to the filter so I'm not sure what the issue is. Can you assist?
Option Explicit
'
' Change Insight's Focus Time Appointments
' Source: https://www.slipstick.com/outlook/change-insights-focus-time-appointments/
Public Sub ChangeInsights()
Dim calFolder As folder
Dim CalItems As Outlook.Items
Dim ResItems As Outlook.Items
Dim sFilter As String
Dim Appt As AppointmentItem 'Object
Dim mystart As Date
mystart = Date
Set calFolder = Session.GetDefaultFolder(olFolderCalendar)
Set CalItems = calFolder.Items
' Sort all of the appointments based on the start time
CalItems.Sort "[Start]"
On Error Resume Next
sFilter = "[Start] >='" & Format(mystart, "m/d/yy") & "' AND [Subject] = Focus Time"
Set ResItems = CalItems.Restrict(sFilter)
'Loop through the items in the collection.
For Each Appt In ResItems
With Appt
.Categories = "Deep Work"
'.ReminderSet = False
'.BusyStatus = olTentative
.Save
End With
Next
Set Appt = Nothing
End Sub
Thank you for the tip. I really like the automatically planned focus time slots in my calendar, but the status 'busy' causes people to not being able to call me through Microsoft Teams during these time slots, which is a bit rigorously. Now I would like to have this code ChangeInsights () to be started when Outlook starts. So I made it as following, which you can just paste in ThisOutlookSession. Maybe handy for others. REMARK: Because somewhere in my profile my language is Dutch I had to change it to 'Focustijd'. If yours is English, replace the 2 'Focustijd' pieces for 'Focus Time'. Also after the first restart of Outlook, you can change the color of the Category 'Focus Time' if you like. Private Sub Application_Startup() Dim calFolder As Folder Dim CalItems As Outlook.Items Dim ResItems As Outlook.Items Dim sFilter As String Dim Appt As AppointmentItem 'Object Set calFolder = Session.GetDefaultFolder(olFolderCalendar) Set CalItems = calFolder.Items ' Sort all of the appointments based on the start time CalItems.Sort "[Start]" On Error Resume Next sFilter = "[Subject] = Focustijd" Set ResItems = CalItems.Restrict(sFilter) 'Loop through the items in the collection. For Each Appt In ResItems With Appt .Categories = "Focustijd" .ReminderSet… Read more »
Thanks for the tip!!