none
add other user's folder via script RRS feed

  • Question

  • Hi all,

    I was asked to perform the following configuration on our Outlook 2013:

    File --> Open&export --> add other user's folder and then select the folder "Contacts" of a particular mailbox.

    All works fine. But.... I was asked to attach 10 contacts folders on about 50 computers. I was wondering if there is a method to automate this task via script. It would be acceptable a configurable script to run on each computer, then I would try to execute it remotely.

    Thank you

    Thursday, June 18, 2015 2:19 PM

Answers

  • Hi Maurice,

    You need to use the GetSharedDefaultFolder method of the Namespace class which returns a Folder object that represents the specified default folder for the specified user.

    Sub ResolveName() 
     Dim myNamespace As Outlook.NameSpace 
     Dim myRecipient As Outlook.Recipient 
     Dim CalendarFolder As Outlook.Folder 
     Set myNamespace = Application.GetNamespace("MAPI") 
     Set myRecipient = myNamespace.CreateRecipient("Eugene Astafiev") 
     myRecipient.Resolve 
     If myRecipient.Resolved Then 
      Call ShowCalendar(myNamespace, myRecipient) 
     End If
    End Sub 
     
    Sub ShowCalendar(myNamespace, myRecipient) 
     Dim CalendarFolder As Outlook.Folder 
     Set CalendarFolder = _ 
     myNamespace.GetSharedDefaultFolder(myRecipient, olFolderContacts) 
     CalendarFolder.Display
    End Sub

    Friday, June 19, 2015 7:36 AM

All replies

  • Hi,

    Since this issue is about the development of Outlook, I'll move this thread to Outlook for Developers forum.

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,

    Melon Chen
    TechNet Community Support


    It's recommended to download and install Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office programs. Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Friday, June 19, 2015 5:44 AM
  • Hello Maurice,

    The Outlook object model provides the Add method of the Folders class which creates a new folder in the Folders collection. For example, a VBA macro is listed below:

    Sub AddContactsFolder() 
     Dim myNameSpace As Outlook.NameSpace 
     Dim myFolder As Outlook.Folder 
     Dim myNewFolder As Outlook.Folder 
     
     Set myNameSpace = Application.GetNamespace("MAPI") 
     Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts) 
     Set myNewFolder = myFolder.Folders.Add("My Contacts") 
    End Sub 


    Friday, June 19, 2015 6:37 AM
  • Thank you for your answer. It works, but it doesn't solve my problem. I need to open another user's (another mailbox) contacts folder, and it will consequently appear under "Shared Contacts" in People section of Outlook.

    I can do it manually with:

    File --> Open&export --> add other user's folder. This last click opens the GAL, then I can select a mailbox and specify which folder I want to open (in my case, Contacts). 

    but I'd like to do it programmatically. So I think the script should query the GAL, because the folder I want to open belongs to a mailbox that isn't connected to Outlook.

    Obviusly I have the permission to open this particular folder, permissions are given with 

    Add-MailboxFolderPermission -Identity "Mailbox1:\Contacts" -User user1 -AccessRights ReadItems

    so I don't have permission on entire Mailbox1 but only on its Contacts folder.



    Friday, June 19, 2015 7:22 AM
  • Hi Maurice,

    You need to use the GetSharedDefaultFolder method of the Namespace class which returns a Folder object that represents the specified default folder for the specified user.

    Sub ResolveName() 
     Dim myNamespace As Outlook.NameSpace 
     Dim myRecipient As Outlook.Recipient 
     Dim CalendarFolder As Outlook.Folder 
     Set myNamespace = Application.GetNamespace("MAPI") 
     Set myRecipient = myNamespace.CreateRecipient("Eugene Astafiev") 
     myRecipient.Resolve 
     If myRecipient.Resolved Then 
      Call ShowCalendar(myNamespace, myRecipient) 
     End If
    End Sub 
     
    Sub ShowCalendar(myNamespace, myRecipient) 
     Dim CalendarFolder As Outlook.Folder 
     Set CalendarFolder = _ 
     myNamespace.GetSharedDefaultFolder(myRecipient, olFolderContacts) 
     CalendarFolder.Display
    End Sub

    Friday, June 19, 2015 7:36 AM