This project has moved. For the latest updates, please go here.

Outlook: GetNavigationModule returns a NavigationModule, but I need a CalendarModule object instead

Feb 2, 2016 at 3:44 PM
Here's my bit of code that has the problem.
Dim ObjPane As Outlook.NavigationPane = Application.ActiveExplorer.NavigationPane
Dim objCalendarModule As Outlook.CalendarModule = ObjPane.Modules.GetNavigationModule(OlNavigationModuleType.olModuleCalendar)
This comes up as a compile-time error on the second line: "Value of type 'NetOffice.OutlookApi.NavigationModule' cannot be converted to 'NetOffice.OutlookApi.CalendarModule'".

Based on Microsoft's own code sample on this page, it should be possible to make this assignment, and indeed it was until I encountered the issue in the conversion to NetOffice just now.
Link: https://msdn.microsoft.com/EN-US/library/office/ff863591.aspx

What could be going wrong?
Thanks very much,
Sandra
Coordinator
Feb 6, 2016 at 12:34 AM
hey men,

I've been tried you scenario with the Interop Assemblies(Outlook 2015) from Microsoft with the same result.
NavigationModule and CalendarModule doesnt have any relationship.
(but its looks like NavigationModule is the common base class for CalendarModule and others)

This means:
a) the documentation is wrong
b) heavy undocumented changes in office 2015 and above

I doesnt have access to my virtual test machines right now(working for a project in another country)
At monday i want try to figure out this way from the documentation is possible in older Office versions -
but i dont think so.

(if its helpful for your you to use

Outlook.MAPIFolder calendar = Application.Session.GetDefaultFolder (Outlook.OlDefaultFolders.olFolderCalendar);

instead?)

*Sebastian
Feb 9, 2016 at 6:09 PM
Hi!

Thanks for your reply. The documentation wasn't always wrong - it is how my current Office 2010 addin does it without issue.

I've already gone down another road - going to bite the bullet and get Add-in Express. All my code just works with the trial version, and I've spent too much time on this already. :(

Unfortunately, I can't use the OutlookMAPIFolder option. I think that just gets the user's calendar. I actually need the CalendarModule so that I can get a reference to the Other Calendars group...
Dim objGroup As Outlook.NavigationGroup
objGroup = objCalendarModule.NavigationGroups.GetDefaultNavigationGroup(Outlook.OlGroupType.olOtherFoldersGroup)
... and eventually check if the user's department SharePoint calendar is under objGroup.NavigationFolders. If not, I add it.

I also found a bug in NetOffice and submitted the fix in GitHub. It's when you want to register your addin under HKLM.

And I also hit another showstopper with the NetOffice conversion. ( I don't mean to sideline the topic, but I wanted to let you know in case you want to take a look and make enhancements.) This one was with trying to handle the ModuleSwitch event
Private ObjPane As Outlook.NavigationPane  ' needs to be defined outside of the startup event handler because it is referenced the definition of the ModuleSwitch event handler
ObjPane = Application.ActiveExplorer.NavigationPane
AddHandler ObjPane.ModuleSwitchEvent, New Outlook.NavigationPane_ModuleSwitchEventHandler(AddressOf NavigationPane_ModuleSwitch)
But in the handler, I am given Nothing for theModule. I need to check if it's the Calendar module that was opened, but can't.
    Private Sub NavigationPane_ModuleSwitch(ByVal theModule As Outlook.NavigationModule)
Thanks for your awesome work, and it was a pleasure working with it, but at least in my case, it didn't seem complete in the areas that I needed.