如何从excel复制数据并将其粘贴到Outlook正文中并发送

时间:2019-07-13 03:10:50

标签: excel vba outlook outlook-vba

如何将数据从excel中的第一行复制到最后一个内容行,并将其直接粘贴到Outlook正文中,然后将其发送“不使用任何其他临时excel”

1 个答案:

答案 0 :(得分:0)

发送电子邮件消息的Outlook对象模型中的MailItem类的Send方法。

以下是用于创建新MailItem并将其发送出去的示例VB.NET代码:

Private Sub CreateSendItem(Application As Outlook.Application)
    Dim mail As Outlook.MailItem = Nothing
    Dim mailRecipients As Outlook.Recipients = Nothing
    Dim mailRecipient As Outlook.Recipient = Nothing
    Try
        mail = Application.CreateItem(Outlook.OlItemType.olMailItem)
        mail.Subject = "A programatically generated e-mail"
        mailRecipients = mail.Recipients
        mailRecipient = mailRecipients.Add("Eugene Astafiev")
        mailRecipient.Resolve()
        If (mailRecipient.Resolved) Then
            mail.Send()
        Else
            System.Windows.Forms.MessageBox.Show(
                "There is no such record in your address book.")
        End If
    Catch ex As Exception
        System.Windows.Forms.MessageBox.Show(ex.Message,
            "An exception is occured in the code of add-in.")
    Finally
        If Not IsNothing(mailRecipient) Then Marshal.ReleaseComObject(mailRecipient)
        If Not IsNothing(mailRecipients) Then Marshal.ReleaseComObject(mailRecipients)
        If Not IsNothing(mail) Then Marshal.ReleaseComObject(mail)
    End Try
End Sub

您可能会找到How To: Create and send an Outlook message programmatically文章。

在Outlook中使用正文的主要方法有三种:

  1. Body
  2. HTMLBody
  3. 字编辑器。 Inspector类提供WordEditor属性,该属性从代表消息正文的Word对象模型返回Document类的实例。 Outlook使用Word作为电子邮件编辑器。

您可以在Chapter 17: Working with Item Bodies中阅读有关此内容的更多信息。哪种方法由您决定。