Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Open a non-default shared calendar in Oulook using VBA

Posted on 2013-06-03
5
Medium Priority
?
3,008 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

610 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