如何更新非默认邮箱联系人与分发列表?

huangapple go评论52阅读模式
英文:

How can one update non-default mailbox contacts with a distribution list?

问题

Here are the translated parts of your code:

这是基于我在网上找到的一个示例。它在默认邮箱中创建一个分发列表。

我想要为除默认邮箱之外的任何邮箱创建一个分发列表。

我想要选择创建分发列表的邮箱。
我想要在创建分发列表时提示用户确认正确的联系人窗口已打开。

如何解决以下两行?

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

Please note that code translation can vary depending on specific requirements and context, so you may need to adapt these translations accordingly.

英文:

This is based on an example I found on the web. It creates a distribution list in the default mailbox.

I want to create a distribution list for any mailbox other than the default.

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

I want to select the mailbox the distribution list will be created in.
I want to prompt the user to confirm the correct Contacts window is open when creating the distribution list.

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

How do I resolve the below two lines?

  • Set oItem = need some code to create the distribution list in the currently selected window
  • Set oRecipient = need some code to create the recipient in the new distribution list

答案1

得分: 0

请使用MAPIFolder.Items.Add而不是Application.CreateItem,其中MAPIFolder需要来自Outlook存储库而不是默认的存储库。

尝试以下更改:

Dim oStore As Outlook.Store
Dim oFolder As Outlook.MAPIFolder
Set oStore = Application.ActiveExplorer.CurrentFolder.Store
Set oFolder = oStore.GetDefaultFolder(olFolderContacts)
Set oItem = oFolder.Items.Add("IPM.DistList")
英文:

Instead of using Application.CreateItem, use MAPIFolder.Items.Add, where MAPIFolder needs to come from the Outlook store other than the default one.

Try the following change:

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")

huangapple
  • 本文由 发表于 2023年4月17日 06:49:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76030697.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定