VBA Outlook-从Excel作为收件人检索电子邮件地址 [英] VBA outlook - retrieve email address from excel as recipient

查看:136
本文介绍了VBA Outlook-从Excel作为收件人检索电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从excel单元中检索电子邮件地址,并将其复制为Outlook中的收件人.

I would like to retrieve the email addresses from excel cells and copy them as recipients on outlook.

但是,Outlook上的收件人"和抄送"为空.

However, the "To" and "CC" on outlook are empty.

输入和输出:

单元格A1是我要发送到" 的电子邮件地址.

Cell A1 is the email address which I want to "send to".

单元格A2是我要抄送"到的电子邮件地址.

Cell A2 is the email address which I want to "CC to".

我的VBA代码:

Sub Button1_Click()

    Dim OutApp As Object
    Dim OutMail As Object




    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(olMailItem)



    On Error Resume Next
    With OutMail
        .To = Cells("A1")
        .CC = Cells("A2")
        .BCC = ""
        .Subject = "This is the Subject line"

    End With
    On Error GoTo 0


    Set OutMail = Nothing
    Set OutApp = Nothing

End Sub

推荐答案

您需要添加收件人,而不是To,CC或BCC属性.这些属性仅包含显示名称.收件人集合应用于修改此属性.例如:

You need to add a recipient, not the To, CC or BCC properties. These properties contain the display names only. The Recipients collection should be used to modify this property. For example:

Sub CreateStatusReportToBoss()  
   Dim myItem As Outlook.MailItem  
   Dim myRecipient As Outlook.Recipient 
   Set myItem = Application.CreateItem(olMailItem)  
   Set myRecipient = myItem.Recipients.Add("Dan Wilson")  
   myItem.Subject = "Status Report"  
   myItem.Display  
End Sub

您可能会发现以下文章有帮助:

You may find the following articles helpful:

这篇关于VBA Outlook-从Excel作为收件人检索电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆