为什么我没有附件时电子邮件正文为空?我想念什么?任何帮助表示赞赏!下面的代码:
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文档的文件路径(该文件路径可能具有...
Save
方法。