Use this macro to select multiple calendars and open them in overlay mode. If you are using iCloud and don't want the iCloud calendars selected by default, you can use this method to deselect the iCloud calendars. See Deselect iCloud Calendars for more information and the necessary code.
This code sample assumes that the calendars are all in the My Calendars group.
If the calendars are all in another group, you can use this line to identify the group and select the calendars in it:
Set objGroup = .Item("group name")
In this code sample, I'm opening calendars #1, 3, and 4 in the My Calendars group. To open 2 and 5 (New Stuff and a mailbox Calendar in the screenshot), I'd use Case 2, 5
When you use Outlook 2013 and all of the calendars are in one group, you can select the group to show all.
To use, set macro security to low, open the VBA editor by pressing Alt+F11 then paste this into a new module. Assign it to a ribbon or toolbar button and run. More complete instructions are at How to use the VBA Editor.
To use a specific view, see set a view at the end of this article.
Sub SelectCalendars() Dim objPane As Outlook.NavigationPane Dim objModule As Outlook.CalendarModule Dim objGroup As Outlook.NavigationGroup Dim objNavFolder As Outlook.NavigationFolder Dim objCalendar As Folder Dim objFolder As Folder Dim i As Integer Set Application.ActiveExplorer.CurrentFolder = Session.GetDefaultFolder(olFolderCalendar) DoEvents Set objCalendar = Session.GetDefaultFolder(olFolderCalendar) Set objPane = Application.ActiveExplorer.NavigationPane Set objModule = objPane.Modules.GetNavigationModule(olModuleCalendar) With objModule.NavigationGroups Set objGroup = .GetDefaultNavigationGroup(olMyFoldersGroup) ' To use a different group ' Set objGroup = .Item("group name") End With For i = 1 To objGroup.NavigationFolders.Count Set objNavFolder = objGroup.NavigationFolders.Item(i) Select Case i ' Enter the calendar index numbers you want to open Case 1, 3, 4 objNavFolder.IsSelected = True ' Set to True to open side by side objNavFolder.IsSideBySide = False Case Else objNavFolder.IsSelected = False End Select Next ' set the view here Set objPane = Nothing Set objModule = Nothing Set objGroup = Nothing Set objNavFolder = Nothing Set objCalendar = Nothing Set objFolder = Nothing End Sub
Automatically select specific calendars when switching to the calendar module
If you want to always have certain calendars selected when you switch to the calendar module, you can add an Application_Startup macro to the code. Every time you select the calendar module, the calendars listed in the Case statement will be selected.
To use this macro, add it to ThisOutlookSession. Click in the Application_Startup macro and press Run to enable it without restarting Outlook.
Dim WithEvents objPane As NavigationPane Private Sub Application_Startup() Set objPane = Application.ActiveExplorer.NavigationPane End Sub Private Sub objPane_ModuleSwitch(ByVal CurrentModule As NavigationModule) Dim objPane As NavigationPane Dim objModule As CalendarModule Dim objGroup As NavigationGroup Dim objNavFolder As NavigationFolder Dim objCalendar As Folder Dim objFolder As Folder Dim i As Integer If CurrentModule.NavigationModuleType = olModuleCalendar Then Set Application.ActiveExplorer.CurrentFolder = Session.GetDefaultFolder(olFolderCalendar) DoEvents Set objCalendar = Session.GetDefaultFolder(olFolderCalendar) Set objPane = Application.ActiveExplorer.NavigationPane Set objModule = objPane.Modules.GetNavigationModule(olModuleCalendar) With objModule.NavigationGroups Set objGroup = .GetDefaultNavigationGroup(olMyFoldersGroup) ' To use a different group ' Set objGroup = .Item("group name") End With For i = 1 To objGroup.NavigationFolders.Count Set objNavFolder = objGroup.NavigationFolders.Item(i) Select Case i ' Enter the calendar index numbers you want to open Case 1, 3, 4 objNavFolder.IsSelected = True ' Set to True to open side by side objNavFolder.IsSideBySide = False Case Else objNavFolder.IsSelected = False End Select Next ' set the view here End If Set objPane = Nothing Set objModule = Nothing Set objGroup = Nothing Set objNavFolder = Nothing Set objCalendar = Nothing Set objFolder = Nothing End Sub
Select Specific Calendar When Outlook Starts
Outlook is starting with the user's Calendar and not the one we want selected.
If the calendar is in an account in your profile, you can select the calendar in File, Options, Advanced and select it as the startup folder. If it's not available to select, you might be able to use a command line switch to choose the correct calendar. See "Choose the Folder Outlook Starts Up In" for details.
This code selects a specific calendar when Outlook starts up. You need to set Outlook to start in the Calendar folder for it to work.
Private Sub Application_Startup() Dim objPane As NavigationPane Dim objModule As CalendarModule Dim objGroup As NavigationGroup Dim objNavFolder As NavigationFolder Set objPane = Application.ActiveExplorer.NavigationPane Set objModule = objPane.Modules.GetNavigationModule(olModuleCalendar) With objModule.NavigationGroups Set objGroup = .GetDefaultNavigationGroup(olMyFoldersGroup) End With On Error Resume Next Set objNavFolder = objGroup.NavigationFolders.Item(2) DoEvents objNavFolder.IsSelected = True objNavFolder.IsSideBySide = False DoEvents Set objNavFolder = objGroup.NavigationFolders.Item(1) objNavFolder.IsSelected = False 'set the view here End Sub
Deselect iCloud Calendars
Many iCloud users don't appreciate that Apple has all iCloud calendars selected by default when you open Outlook. If you are one of these users, you can use the following code sample to deselect the iCloud calendars. Replace the block of code between With objModule.NavigationGroups and the last End If in the automatic macro above with the code below.
With objModule.NavigationGroups Set objGroup = .Item("iCloud") End With For i = 1 To objGroup.NavigationFolders.Count Set objNavFolder = objGroup.NavigationFolders.Item(i) Select Case i ' Enter the calendar index numbers you want to close Case 1, 2 If objNavFolder.IsSelected = True Then objNavFolder.IsSelected = False Else End If ' we'll deselect any we missed Case Else objNavFolder.IsSelected = False End Select Next End If
Set a specific view on the Calendar
Outlook will generally use the last view you used on the calendar. If you want to use a specific view with the macros above, you can set the view in the code.
Add this code before the end of the macros above to set the calendar to the day view. If the macro has an End if at the end, add it before the End If.
Dim objViews As Views Dim objView As View Set objViews = Application.ActiveExplorer.CurrentFolder.Views Set objView = objViews.Item("Calendar") With objView ' Set the calendar view to show a ' single day. .CalendarViewMode = olCalendarViewDay End With objView.Apply
Name | Description |
---|---|
olCalendarView5DayWeek | Displays a 5-day week. |
olCalendarViewDay | Displays a single day. |
olCalendarViewMonth | Displays a month. |
olCalendarViewMultiDay | Displays a number of days equal to the DaysInMultiDayMode property value of the CalendarView object. |
olCalendarViewWeek | Displays a 7-day week. |
More Information
How to: Add a Custom Folder to a Group and Display it in Overlay Mode by Default (MSDN)
Macro code that displays several shared calendars (Outlookcode.com)
I am selecting 15 calendars under a "shared calendars" group and that is working. But by default it is selecting them all under both my default calendar and schedule view. I then have to toggle day view and Schedule View to get the stacked one to go away. Screenshot here.
Is there a way that I can choose Schedule View by default?
I've successfully used this code to open all my calendars in one overlaid weekly view. What I haven't managed to do is to get Outlook to set the specific calendar to use for New Appointment or New Meeting. Which calendar gets chosen seems almost random, though it seems to be consistent after an application of the macro it may change on the next application.
Ideally, I want the New ... functions to default to my personal calendar.
Diane,
Thanks so much for "Automatically select specific calendars when switching to the calendar module." It does a great job of displaying my three calendars (two shared) in one.
I have two questions:
1) With Outlook set to start in Calendar, it only displays Calendar on startup. My workaround is to start in Contacts and switch to Calendar. But is there a way to force objPane_ModuleSwitch to run on startup?
2) The first time the calendars are displayed, the third one is selected. Every time after that it's the first one. How can the first one be selected all the time?
I tried
For i = objGroup.NavigationFolders.Count To 1 Step -1
but then the second folder was selected the first time; still the first one after that.
Best,
Walt
Just realised my question is essentially the same as the second question here.
Hi,
what code can I use after the calendar selection to just go (back) to the default inbox email folder? I'm now in the calendar view.
BR
You'll add a line to change the module to olModuleMail - add it at the end and it should move you back to the mail module. (I'll test it to verify)
First bug: you need to either use a new object name or change the DIM:
Dim objModule 'As CalendarModule
Beyond that, I'm still getting errors if I try to set a calendar format then switch back using code.
I need some help if possible. I use Outlook 2016 running on an Intel compute stick hooked up to a 65" TV. I want Outlook to open and display 3 Internet calendars (Google Calendars ics) in column view. I used the code above such that when I select the calendar icon in Outlook all 3 calendars open perfectly. However, the last part I'm stuck on is how to I get Outlook to open in that view by default, that is, startup and automatically display the 3 calendars. I can select one Internet calendar to open in the advanced options but not all 3 at once. Can this be achieved by coding?
Thanks,
Jerry
I have never tried it, but it should work. (It actually should remember the last selected calendars (assuming outlook closes correctly and doesn't crash), if you started in email or outlook today and switched to the calendar manually.)
From https://www.slipstick.com/developer/code-samples/select-multiple-calendars-outlook/#start
This set of lines opens the second group:
Set objNavFolder = objGroup.NavigationFolders.Item(2)
DoEvents
objNavFolder.IsSelected = True
objNavFolder.IsSideBySide = False
DoEvents
if the calendars are all in that group, they should open, otherwise, copy those lines and change the group #.
if they aren't in the same group, then you can merge parts of the first macro with this.
Diane,
sorry this is the correct question. ignore previous.
thanks for the writeup. have been using for a while. outlook must have auto-updated. now get a compile error on
Set objCalendar = Session.GetDefaultFolder(olFolderCalendar)
error = obect library feature not supported.
an you help ? thanks
Diane,
thanks for the writeup. have been using for a while. outlook must have auto-updated. now get a compile error on
Set objModule = objPane.Modules.GetNavigationModule(olModuleCalendar)
error = obect library feature not supported.
an you help ? thanks
Hey Diane!
How might this look different if I wanted to select a calendar based on its name?
Thanks!
you can replace the index number with a name but if it's not in the default group you need to set the group it's in.
With objModule.NavigationGroups
' Set objGroup = .GetDefaultNavigationGroup(olMyFoldersGroup)
Set objGroup = .Item("group name")
End With
Set objNavFolder = objGroup.NavigationFolders.Item("Alpha")
objNavFolder.IsSelected = True
objNavFolder.IsSideBySide = False
Sorry to bother again!
I had set the correct group I wanted the code to grab the calendar from - however upon strictly replacing the index number with a name - I received some errors :( Below is the part of code I would have changed.
For i = 1 To objGroup.NavigationFolders.Count
Set objNavFolder = objGroup.NavigationFolders.Item(i)
Select Case i
' Enter the calendar index numbers you want to open
Case Room 01 100
objNavFolder.IsSelected = True
I'm sure I've done something incorrectly, or that I've perhaps misread your instructions. Did I replace the index number with the name incorrectly?