Solved

Open a non-default shared calendar in Oulook using VBA

Posted on 2013-06-03
5
2,267 Views
Last Modified: 2013-06-05
I'm trying to open a non-default shared calendar in Outlook using VBA but I only know how to open the default one. I have spent a considerable amount of time researching this online but no luck. Any help would be greatly appreciated.

The user name of the shared calendar is "John Burns" and the non-default calendar name is "Van".

My code to retrieve the default shared calendar is :

    Dim myOlApp As Outlook.Application
    Dim myNms As Outlook.NameSpace
    Dim myFolder As Outlook.MAPIFolder
    Dim myRecipient As Outlook.Recipient
    Dim myExplorer As Outlook.Explorer
    Dim SharedFolder As Outlook.MAPIFolder
   
    Set myOlApp = CreateObject("Outlook.Application")    
    Set myNms = myOlApp.GetNamespace("MAPI")
    Set myFolder = myNms.GetDefaultFolder(olFolderCalendar)
    Set myExplorer = myOlApp.ActiveExplorer
    Set myExplorer.CurrentFolder = myFolder
   
    Set myRecipient = myNms.CreateRecipient("John Burns")
    Set SharedFolder = myNms.GetSharedDefaultFolder(myRecipient, olFolderCalendar)
   
    myExplorer.SelectFolder SharedFolder
0
Comment
Question by:CAGreenlaw
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 39217669
Hi, CAGreenlaw.

You can use the following function to open any Outlook folder, default or otherwise.  Here's how to call it

Set myFolder = OpenOutlookFolder("Path to the folder you want to open")

Function OpenOutlookFolder(strFolderPath)
    ' Purpose: Opens an Outlook folder from a folder path.'
    ' Written: 4/24/2009'
    ' Author:  BlueDevilFan'
    ' Outlook: All versions'
    Dim arrFolders, varFolder, bolBeyondRoot
    On Error Resume Next
    If strFolderPath = "" Then
        Set OpenOutlookFolder = Nothing
    Else
        Do While Left(strFolderPath, 1) = "\"
            strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
        Loop
        arrFolders = Split(strFolderPath, "\")
        For Each varFolder In arrFolders
            Select Case bolBeyondRoot
                Case False
                    Set OpenOutlookFolder = olkSes.Folders(varFolder)
                    bolBeyondRoot = True
                Case True
                    Set OpenOutlookFolder = OpenOutlookFolder.Folders(varFolder)
            End Select
            If Err.Number <> 0 Then
                Set OpenOutlookFolder = Nothing
                Exit For
            End If
        Next
    End If
    On Error GoTo 0
End Function

Open in new window

0
 

Author Comment

by:CAGreenlaw
ID: 39223113
Thanks so much for your quick response BlueDevilFan. I'm not sure how to make this code work for me though (ie. How do I determine the path to the other user's calendar?). I'm trying to open a shared non-default calendar that hasn't already been added to my profile. I think I need to utilize the GetSharedDefaultFolder method but it only returns the default calendar from the user. The other user has several calendars and I need to pick the one called Van and open it. Any ideas?
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 39223192
You'll need to add the calendar to your profile.  Once you've added it to your profile, then you'll modify the line indicated by my comment in the code I provided.  

A folder path in Outlook is essentially the same as a folder path in the file system.  The one difference being that Outlook folder paths do not include a drive letter.  The path to a folder is a list of all the folders from the root to the target folder with each folder name separated from the preceding folder name by a backslash (i.e. \).  Consider the following folder structure:

Mailbox - Doe, John
    - Calendar
    - Inbox
    - Tasks
Personal Folders
    + Marketing
        + Proposals
        + Reviews
    + Projects
        + Project 1
        + Project 2

Open in new window


The path to "Inbox" is "Mailbox - Doe, John\Inbox".
The path to "Reviews" is "Personal Folders\Marketing\Reviews".
The path to "Project 1" is "Personal Folders\Projects\Project 1".

The path to a folder in someone else's mailbox will normally be something like

Mailbox - Doe, John\Calendars\Van

or

john_doe@company.com\Calendars\Van

depending on which version of Outlook you're using.
0
 

Author Closing Comment

by:CAGreenlaw
ID: 39223306
Wow, you really know your stuff BlueDevilFan. Thank you so much, it worked like a charm!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39224103
You're welcome, CAGreenlaw.  Glad I could help out.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now