在 outlook 中使用 vba,如何使用通讯组列表更新非默认邮箱联系人

问题描述 投票:0回答:1

这是基于我在网上找到的一个例子,在默认邮箱中创建通讯组列表时有效。它适用于为默认文件夹创建通讯组列表,但不适用于默认邮箱以外的任何邮箱。

Dim oNameSpace As Outlook.NameSpace
Dim oRecipient As Outlook.Recipient


Set oNameSpace = Application.GetNamespace("MAPI")
Set oRecipient = oNameSpace.CreateRecipient("Some Person")
oRecipient.Resolve

If oRecipient.Resolved Then

   Set oItem = Application.CreateItem(olDistributionListItem)
   Set oRecipient = Application.Session.CreateRecipient("Some User")
   oRecipient.Resolve

   If oRecipient.Resolved Then
      oItem.AddMember oRecipient
      'Add note to list and display
      oItem.DLName = "Northwest -------------------"
      objItem.Body = "Regional Sales Manager - NorthWest"
      oItem.Save
   End If

End If

我希望能够选择将在下面的代码中创建通讯组列表的邮箱将提示用户确认在创建通讯组列表时打开了正确的联系人窗口

Dim oParent As Object

Set oParent = Application.ActiveExplorer.CurrentFolder.Parent

Resp = MsgBox("Acting on Account: " & oParent & vbCrLf & vbCrLf & "OK to Continue, Cancel to Quit", vbOKCancel)
If Resp = vbCancel Then
   End
End If

问题是解决以下两行

  • Set oItem = 需要一些代码来在当前选定的窗口中创建分发列表
  • Set oRecipient = 需要一些代码来在新的分发列表中创建收件人

我确实审查了所有建议的问题并测试了那些看起来很有希望但没有成功的问题

vba outlook contacts distribution
1个回答
0
投票

而不是使用

Application.CreateItem
,使用
MAPIFolder.Items.Add
,其中
MAPIFolder
需要来自默认商店以外的Outlook商店。

尝试以下更改:

Dim oStore As Outlook.Store
Dim oFolder As Outlook.MAPIFolder
Set oStore = Application.ActiveExplorer.CurrentFolder.Store
set oFolder = Store.GetDefaultFolder(olFolderContacts)
Set oItem = oFolder.Items.Add("IPM.DistList")
© www.soinside.com 2019 - 2024. All rights reserved.