none
Outlook 2010 + VB.Net - How to open and display a shared calendar from a VB form app. RRS feed

  • Question

  • Hi Team,
         I have written a desktop tool  in VB (Visual Studio 2010) for my work environment to give users easy access to all of the common things they run.

    Before I get into it; All users have access to the shared calendars from Outlook.

    One of my challenges is to give users a 'One Click' access to shared folders via this tool.
    For example, a shared calendar is used for taking meeting room bookings or booking a phone bridge number etc.

    Being a novice at this; Is it possible to open/view/edit a shared calendar without necessarily launching Outlook?

    If this can be done; code samples would be great.

    cheers,
    MoJo MiO

    Wednesday, January 8, 2014 3:19 AM

Answers

  • Hello MoJo,

    Most probably you didn't add the following statement at the beginning of the file:

    Imports Outlook = Microsoft.Office.Interop.Outlook
     
    

    Please take a look at the Automating Outlook from a Visual Basic Application and Programming samples that can reference items and folders in Outlook by using Visual Basic .NET articles that describe all the required steps in depth (though old Outlook versions may be described). Also you can find a sample application written in C#/ VB.NET and listed in the code gallery - C# app automates Outlook and VB app automates Outlook (VBAutomateOutlook).  

    The GetSharedDefaultFolder method just returns a Folder object that represents the specified default folder for the specified user. It doesn't display any dialogs or pop-up windows. You can find the following sample code on the MSDN page:

    ' GetSharedDefaultFolder:

        Sub Test()
            Dim objOutlook As Outlook._Application
            objOutlook = New Outlook.Application()
            Dim objNS As Outlook._NameSpace = objOutlook.Session
            Dim objRecipient As Outlook.Recipient = _
                objNS.CreateRecipient("John Smith")
            If objRecipient.Resolve Then
                Dim objFolder As Outlook.MAPIFolder = _
                    objNS.GetSharedDefaultFolder(objRecipient, _
                    Outlook.OlDefaultFolders.olFolderCalendar)
                Console.Write(objFolder.Name)
            Else
                Console.Write("Recipient could not be resolved.")
            End If
        End Sub


    • Marked as answer by Marvin_Guo Wednesday, January 15, 2014 11:35 AM
    Wednesday, January 8, 2014 12:09 PM

All replies

  • What exactly do you mean by "open/view/edit"? What exactly will display that folder if Outlook is not open?

    You can certainly access shared folders using Namespace.GetSharedDefaultFolder without making any Outlook windows visible.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, January 8, 2014 5:30 AM
  • Hi Dmitri
         Merry Christmas.

    If I use Namespace.GetSharedDefaultFolder, will this pop up a window with the shared calendar or do I need to create a form to present the data ?

    Sorry if I sound a 'little slow' I'm new to VB programming.

    cheers,
    MoJo MiO

    Wednesday, January 8, 2014 5:37 AM
  • Tripping over my feet....

    To start off I added this declaration:

    Dim CalendarFolder As Outlook.Folder

    I get "Type 'Outlook.Folder' is not defined.
    So I am guessing I need to add a .NEt or COM reference.
    I tried to resolve this error by adding "Microsoft Outlook 14.0 Object Library".
    It didn't work. :-(

    Any suggestions / what am I missing ?


    • Edited by MoJo MiO Wednesday, January 8, 2014 6:11 AM
    Wednesday, January 8, 2014 6:10 AM
  • Hello MoJo,

    Most probably you didn't add the following statement at the beginning of the file:

    Imports Outlook = Microsoft.Office.Interop.Outlook
     
    

    Please take a look at the Automating Outlook from a Visual Basic Application and Programming samples that can reference items and folders in Outlook by using Visual Basic .NET articles that describe all the required steps in depth (though old Outlook versions may be described). Also you can find a sample application written in C#/ VB.NET and listed in the code gallery - C# app automates Outlook and VB app automates Outlook (VBAutomateOutlook).  

    The GetSharedDefaultFolder method just returns a Folder object that represents the specified default folder for the specified user. It doesn't display any dialogs or pop-up windows. You can find the following sample code on the MSDN page:

    ' GetSharedDefaultFolder:

        Sub Test()
            Dim objOutlook As Outlook._Application
            objOutlook = New Outlook.Application()
            Dim objNS As Outlook._NameSpace = objOutlook.Session
            Dim objRecipient As Outlook.Recipient = _
                objNS.CreateRecipient("John Smith")
            If objRecipient.Resolve Then
                Dim objFolder As Outlook.MAPIFolder = _
                    objNS.GetSharedDefaultFolder(objRecipient, _
                    Outlook.OlDefaultFolders.olFolderCalendar)
                Console.Write(objFolder.Name)
            Else
                Console.Write("Recipient could not be resolved.")
            End If
        End Sub


    • Marked as answer by Marvin_Guo Wednesday, January 15, 2014 11:35 AM
    Wednesday, January 8, 2014 12:09 PM
  • Hi Mojo,

    No, it won't. There are two possible ways for presenting the data:

    1. Show your own form from the shared folder.

    2. You can call the Display method of the Folder class. It displays a new Explorer object for the folder.

    So, it is up to your which ways is to choose.

    Wednesday, January 8, 2014 12:13 PM