Vba 是否有方法列出当前Outlook会话中可访问的收件箱?
我希望在Outlook会话中检索电子邮件收件箱列表(所有可访问的收件箱,包括主收件箱、共享收件箱和委派收件箱)。我所需要的只是这些收件箱的字符串电子邮件地址,所以下面的示例代码只是在消息框中打印出来(当然,这并不是实际发生的事情!) 我想我只是太傻了,找不到相关的属性来循环 以下内容似乎未返回会话已授权访问的收件箱:Vba 是否有方法列出当前Outlook会话中可访问的收件箱?,vba,outlook,Vba,Outlook,我希望在Outlook会话中检索电子邮件收件箱列表(所有可访问的收件箱,包括主收件箱、共享收件箱和委派收件箱)。我所需要的只是这些收件箱的字符串电子邮件地址,所以下面的示例代码只是在消息框中打印出来(当然,这并不是实际发生的事情!) 我想我只是太傻了,找不到相关的属性来循环 以下内容似乎未返回会话已授权访问的收件箱: Public Sub PrintAccounts() Dim accounts As Outlook.accounts Set accounts = Applica
Public Sub PrintAccounts()
Dim accounts As Outlook.accounts
Set accounts = Application.Session.accounts
Dim account As Outlook.account
For Each account In accounts
MsgBox account.DisplayName
Next account
End Sub
非常感谢
现在答复:
Private Sub DisplayedMailboxesNames()
Dim colStores As Stores
Dim oStore As Store
Set colStores = Session.Stores
For Each oStore In colStores
Debug.Print ResolveDisplayNameToSMTP(oStore.displayName)
Next
End Sub
Private Function ResolveDisplayNameToSMTP(displayName As String) As String
Dim oRecip As Outlook.Recipient
Dim oEU As Outlook.ExchangeUser
Dim oEDL As Outlook.ExchangeDistributionList
Set oRecip = Application.Session.CreateRecipient(displayName)
oRecip.Resolve
If oRecip.Resolved Then
Select Case oRecip.AddressEntry.AddressEntryUserType
Case OlAddressEntryUserType.olExchangeUserAddressEntry
Set oEU = oRecip.AddressEntry.GetExchangeUser
If Not (oEU Is Nothing) Then
ResolveDisplayNameToSMTP = oEU.PrimarySmtpAddress
End If
Case OlAddressEntryUserType.olExchangeDistributionListAddressEntry
Set oEDL = oRecip.AddressEntry.GetExchangeDistributionList
If Not (oEDL Is Nothing) Then
ResolveDisplayNameToSMTP = oEDL.PrimarySmtpAddress
End If
End Select
End If
End Function
帐户与邮箱不同 将所有可访问的邮箱添加到用户的GUI,然后:
Private Sub DisplayedMailboxesNames()
Dim colStores As Stores
Dim oStore As Store
Dim oRoot As Folder
Set colStores = Session.Stores
For Each oStore In colStores
Set oRoot = oStore.GetRootFolder
Debug.Print oRoot.folderPath
Debug.Print oRoot.Name
Next
End Sub
帐户与邮箱不同 将所有可访问的邮箱添加到用户的GUI,然后:
Private Sub DisplayedMailboxesNames()
Dim colStores As Stores
Dim oStore As Store
Dim oRoot As Folder
Set colStores = Session.Stores
For Each oStore In colStores
Set oRoot = oStore.GetRootFolder
Debug.Print oRoot.folderPath
Debug.Print oRoot.Name
Next
End Sub
太好了,谢谢你!我特别需要的是电子邮件地址,而不是显示姓名,但将此功能与另一个功能结合起来,我成功地检索了电子邮件。这太棒了,谢谢!我特别需要的是电子邮件地址,而不是显示姓名,但将此功能与另一个功能结合后,我成功地检索了电子邮件。通常的过程是制作一个回复帖子,而不是将答案编辑到问题中。在允许的情况下,你可以接受这个答案。通常的程序是做一个答题贴,而不是将答案编辑到问题中。如果允许,你可以接受这个答案。