Results 1 to 5 of 5

Thread: Fetching a Calendar in Outlook

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    Oct 2014
    Posts
    124
    Reputation
    53

    Fetching a Calendar in Outlook

    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:

    Code:
    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 by jwcoleman87; 07-06-2017 at 5:25 PM. Reason: Oops, left my boss's name in the image.

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,207
    Reputation
    2859
    It appears from my web search that you can loop through oCalendar.Folders, where each is a MAPIFolder that is a calendar.
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    Oct 2014
    Posts
    124
    Reputation
    53
    Quote Originally Posted by JohnH View Post
    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:
    Code:
    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\Telet rackOL.tlb". Error accessing the OLE registry. (Exception from HRESULT: 0x8002801C (TYPE_E_REGISTRYACCESS)) TeletrackOL

  4. #4
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,207
    Reputation
    2859
    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.
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  5. #5
    .NET Framework
    .NET 4.5
    Join Date
    Oct 2014
    Posts
    124
    Reputation
    53
    I found a resource that seems to agree with what you are saying:

    http://www.outlookcode.com/codedetail.aspx?id=1836

    It looks like this guy is looking for a folder using "SharePoint Lists" in the Application's namespace. then he goes and finds the Calendar folder in that.

Similar Threads

  1. Question appointment into a second calendar Outlook
    By vornn in forum Third Party Products
    Replies: 2
    Last Post: 03-15-2012, 7:30 AM
  2. Question Calendar Sync with outlook and PDA
    By smdhd3 in forum Third Party Products
    Replies: 0
    Last Post: 07-08-2010, 8:14 PM
  3. Outlook style month calendar
    By gate7cy in forum Windows Forms
    Replies: 3
    Last Post: 08-04-2009, 2:22 PM
  4. How to create an Outlook Calendar?
    By satishkumar in forum Component Development
    Replies: 0
    Last Post: 11-09-2006, 12:41 PM
  5. Programming the Outlook Calendar on PPC?
    By Neal in forum Compact Framework General Discussion
    Replies: 1
    Last Post: 08-10-2006, 6:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •