简体   繁体   中英

outlook shared mailbox contacts in a excel list with VBA

I'm looking for a vba code in excel, he should contacts from a shared mailbox (different exchange account called shared mailbox in outlook) transfer to a excel list, with the normal contacts from outlook it works I used this:

Set nsOutlook = applOutlook.GetNamespace("MAPI") 

Set cfOutlook = nsOutlook.GetDefaultFolder(olFolderContacts)

with Set olcontacts = cfOutlook.Folders("name")

I have used the "name" where is displayed in outlook it not works he not find the folder.

is there a solution without recipient? because there will be several user-all with the same shared mailbox

I hope you can help me.

The Outlook object model provides the GetSharedDefaultFolder method of the Namespace class which returns a Folder object that represents the specified default folder for the specified user. For example:

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("Dan Wilson")  
  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, olFolderCalendar)  
  CalendarFolder.Display  
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM