vba - 如何在Excel VBA中访问联系人组?

标签 vba excel outlook

我正在构建一个 Excel 加载项,它将事件工作簿作为 Outlook 电子邮件模板中的附件发送到特定的联系人组。

我已经获得了前两部分,可以使用下面的代码,但我不确定如何将 .TO 字段设置为联系人组。

Public Sub Mail_Reports()
    Dim rng As Range
    Dim OutApp As Object
    Dim OutMail As Object 

    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    On Error Resume Next

    Set OutApp = CreateObject("Outlook.Application")

    'Set this line to the path and file name of your template
    Set OutMail = OutApp.CreateItemFromTemplate("C:\Users\moses\AppData\Roaming\Microsoft\Templates\test.oft")
    On Error Resume Next

    With OutMail
        '.TO field should be set to the contact group
        .BCC = ""
        .Attachments.Add ActiveWorkbook.FullName
        .HTMLBody = Replace(OutMail.HTMLBody, strOldPeriod, strNewPeriod)
        .Subject = Replace(OutMail.Subject, strOldPeriod, strNewPeriod)
        'To display the email leave as is;  to send the Email, change to .Send
        .Display    'or Send
    End With

    On Error GoTo 0

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

最佳答案

只需使用联系人组的名称(以前称为“通讯组列表”)。我刚刚尝试过,按照 Ron de Bruin's 上的建议网站,并且可以正常工作。

关于vba - 如何在Excel VBA中访问联系人组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10049419/

相关文章:

excel - 导入单元格的值以用于数组中的文本到列分隔时,出现类型不匹配错误

c# - RTD 服务器 C# : Getting "N/A" in deployment

c# - OOF 回复的字体

visual-studio-2010 - 如何实现两个按钮点击事件

c# - 数据库集成和报告生成器

javascript - 网页在 Outlook 中无法正常显示

vba - 复制所选行两次

excel - 我无法访问 'Columns(2)' 的每个单元格,与 '' Range ("B:B")' What kind of range is ' Columns(2)' 不同?

excel - VBA excel键检测

excel - 检测Excel工作簿是否已经打开