?
Solved

Open a non-default shared calendar in Oulook using VBA

Posted on 2013-06-03
5
Medium Priority
?
2,803 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

762 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