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
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
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