Fetching a Calendar in Outlook

jwcoleman87

Well-known member
Joined
Oct 4, 2014
Messages
124
Programming Experience
Beginner
Hello all, something I thought would have been super easy, but after exhausting the google search engine I am coming up dry.

I am able to get my default calendar no problem:

VB.NET:
Imports Microsoft.Office.Core
Imports Microsoft.Office.Interop.Outlook
Imports Microsoft.Office.Tools.Outlook
Public Class TeletrackOL
    'Handles initialization of startup variables
    Private Sub ThisAddIn_Startup() Handles Application.Startup
        Dim mpnNamespace As Outlook.NameSpace = Application.GetNamespace("MAPI")
        Dim oCalendar As Outlook.MAPIFolder = mpnNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
        MsgBox(oCalendar.Name)


    End Sub
End Class

But, apparently selecting a different calendar is not as straight forward and I cannot seem to figure out how to do it. I want this one:

calendar.png
I haven't found a single function that allows me to grab a calendar by name.

Even if all you can do is help me search for resources, that would be greatly appreciated!
 
Last edited:
It appears from my web search that you can loop through oCalendar.Folders, where each is a MAPIFolder that is a calendar.
 
It appears from my web search that you can loop through oCalendar.Folders, where each is a MAPIFolder that is a calendar.

Hmm, will have to try that, but it was my impression (given by the message box) you see in my original code that oCalendar was a calendar "folder", which contains calendar things in it. Not a "folder of" calendars.

The message box in my sample code returns "Calendar"

Which you can see that calendar in the image in my original post.


I think I may have found a solution online. The calendar is the default calendar for a group, and I found you can access a calendar from a group email like so:
VB.NET:
Imports Microsoft.Office.Core
Imports Microsoft.Office.Interop.Outlook
Imports Microsoft.Office.Tools.Outlook
Public Class TeletrackOL
    'Handles initialization of startup variables
    Private Sub ThisAddIn_Startup() Handles Application.Startup
        ResolveName()
    End Sub
    Dim myNamespace As Outlook.NameSpace
    Dim myRecipient As Outlook.Recipient
    Dim CalendarFolder As Outlook.Folder


    Sub ResolveName()


        myNamespace = Application.GetNamespace("MAPI")
        myRecipient = myNamespace.CreateRecipient("**************@email.com")
        myRecipient.Resolve()
        If myRecipient.Resolved Then
            Call ShowCalendar(myNamespace, myRecipient)
        End If
    End Sub


    Sub ShowCalendar(myNamespace, myRecipient)
        Dim CalendarFolder As Outlook.Folder
        CalendarFolder = myNamespace.GetSharedDefaultFolder(myRecipient, Outlook.OlDefaultFolders.olFolderCalendar)
        CalendarFolder.Display()
    End Sub
End Class

This snippet was borrowed from something i found on google. It seems like it will work, but the issue here is that my laptop does not have admin rights at work here :(. So, this line throws an exception:

CalendarFolder = myNamespace.GetSharedDefaultFolder(myRecipient, Outlook.OlDefaultFolders.olFolderCalendar)

System.Runtime.InteropServices.COMException: 'The operation failed because of a registry or installation problem. Restart Outlook and try again. If the problem persists, reinstall.'

Looks like I gotta sneak around the man at work to get some admin rights again.

I'm pretty sure its admin because when I build I receive this error:



Error Cannot register type library "C:\Users\Jonathan.Coleman\OneDrive - Teleplan International N.V\Source\Teletrack\TeletrackOL\bin\Release\TeletrackOL.tlb". Error accessing the OLE registry. (Exception from HRESULT: 0x8002801C (TYPE_E_REGISTRYACCESS)) TeletrackOL
 
oCalendar was a calendar "folder", which contains calendar things in it. Not a "folder of" calendars.
I just found it online somewhere, it is common how things are organized in Outlook, much like in a file system. It is also possible to put a calendar in default calendars parent folder, which is the root personal folder I think.
 

Latest posts

Back
Top