Outlook VBA 为联系人列表中的每个联系人组创建新的电子邮件草稿

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16530164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 21:05:14  来源:igfitidea点击:

Outlook VBA to create new draft email for each Contact Group in contact list

vbaoutlookoutlook-vba

提问by Matt

Is there a VBA script that will

是否有一个 VBA 脚本可以

  • Create a draft email for each Contact Group
  • With the Contact Group's contacts in the "TO" field
  • With a uniform Subject
  • With a uniform Body
  • ...and bonus if the body includes the Signature
  • 为每个联系人组创建电子邮件草稿
  • 在“收件人”字段中使用联系人组的联系人
  • 有统一的主题
  • 拥有统一的身体
  • ...和奖金,如果身体包括签名

Background:In my contact list I have about 50 Contact Groups, each representing a client, and each containing multiple contacts. Once a month, I must email an invoice to each client. This currently entails

背景:在我的联系人列表中,我有大约 50 个联系人组,每个组代表一个客户,每个组包含多个联系人。每月一次,我必须通过电子邮件将发票发送给每个客户。这目前需要

  • creating an email for each of the 50 Contact Groups
  • copying a subject line to each of the 50 drafts
  • copying a body to each of the 50 drafts
  • 为 50 个联系人组中的每一个创建电子邮件
  • 将主题行复制到 50 份草稿中的每一份
  • 将正文复制到 50 个草稿中的每一个

I've found plenty of references for creating emails via VBA, but nothing about using Contact Groups to power it.

我找到了很多通过 VBA 创建电子邮件的参考资料,但没有任何关于使用联系人组为其提供支持的信息。

    Sub NewEmail()
    Dim myOutlook As Outlook.Application
    Dim objMailMessage As Outlook.MailItem
    Set myOutlook = Outlook.Application
    Set objMailMessage = myOutlook.CreateItem(0)
        With objMailMessage
            .To = "" '?
            .Subject = "Email subject"
            .Body = "Email body." 'Msg + Signature?
            .Display
            .Save
            .Close olPromptForSave
        End With
    End Sub

采纳答案by Kazimierz Jawor

At the beginning of your code you need to add references to you 'Contact Group'. Let's assume you have one named 'Grupa Testowa' ('Testing group' in English). So, modify your code this way:

在代码的开头,您需要添加对“联系人组”的引用。假设您有一个名为“Grupa Testowa”(英文为“Testing group”)的人。因此,以这种方式修改您的代码:

Sub NewEmail()
    'new part of the code here
    Dim CF As Folder
    Set CF = Application.Session.GetDefaultFolder(olFolderContacts)

    Dim DLI As DistListItem
    Set DLI = CF.items("Grupa Testowa")

    'your code here with one modification within With...End With
    With objMailMessage
        .To = DLI
    '...rest of your code
    End with
End sub

For further references check DistListItem Objectdescription in MSDN.

如需进一步参考,请查看DistListItem ObjectMSDN 中的说明。