vba Word文档作为电子邮件正文使用“ .display”但不使用“ .send”]] << [

问题描述 投票:0回答:1
我有一个用尽了Excel的代码来创建电子邮件。设置代码以引用我的电子表格上的单元格,以查找用于存放我用于电子邮件正文的Word文档(可能带有或不带有格式和图像)的文件路径。它还会读取电子表格单元格,以获取任何附件的文件路径以及我想要的主题行。该代码应复制doc单词的内容并将其粘贴到电子邮件正文中并发送。在“ .display”上,它可以完美工作并提取完整的Word文档内容以及格式和图像,并显示电子邮件。在“ .send”上,它发送电子邮件并包含主题行,但是如果我没有附件,它将电子邮件正文留空。如果我有附件,则可以在“ .send”命令上正常工作。

为什么我没有附件时电子邮件正文为空?我想念什么?任何帮助表示赞赏!下面的代码:

Sub Send() Dim OutApp As Object Dim OutMail As Object Dim OutMailEditor As Object Dim WordApp As Object Dim WordDoc As Object Dim EmailBodycell As Range Dim SubjectCell As Range Dim sh As Excel.Worksheet Dim Attachment1 As Range Dim Attachment2 As Range Dim Attachment3 As Range Dim Attachment4 As Range Dim Attachment5 As Range Dim ReadReceipt As Range Set OutApp = CreateObject("Outlook.Application") Set WordApp = CreateObject("Word.Application") Set sh = Sheets("Dashboard") Set SubjectCell = sh.Range("D5") 'Cell where subject line is stored Set ReadReceipt = sh.Range("D6") 'Yes/No logic to impose a read receipt Set EmailBodycell = sh.Range("E9") 'Cell where email body word document path is stored Set Attachment1 = sh.Range("E10") Set Attachment2 = sh.Range("E11") Set Attachment3 = sh.Range("E12") Set Attachment4 = sh.Range("E13") Set Attachment5 = sh.Range("E14") Set OutMail = OutApp.CreateItem(0) 'copy/paste the body of the email and change the name Set OutMailEditor = OutMail.GetInspector.WordEditor Set WordDoc = WordApp.Documents.Open(FileName:=EmailBodycell.Value, ReadOnly:=True) WordDoc.Content.Copy OutMailEditor.Range.Paste With OutMail .To = "[email protected]" '.cc = "" .Subject = SubjectCell.Value .ReadReceiptRequested = ReadReceipt.Value On Error Resume Next .Attachments.Add Attachment1.Value On Error Resume Next .Attachments.Add Attachment2.Value On Error Resume Next .Attachments.Add Attachment3.Value On Error Resume Next .Attachments.Add Attachment4.Value On Error Resume Next .Attachments.Add Attachment5.Value On Error GoTo 0 'Restore default error handling '.Display .Send End With Set OutMail = Nothing Set WordDoc = Nothing Set OutApp = Nothing Set WordApp = Nothing End Sub

我有一个用尽了Excel的代码来创建电子邮件。设置代码以引用我的电子表格上的单元格,以查找我存放Word文档的文件路径(该文件路径可能具有...
excel vba ms-word send
1个回答
0
投票
更改电子邮件正文后,您需要调用Save方法。
© www.soinside.com 2019 - 2024. All rights reserved.