【发布时间】:2017-06-20 20:31:52
【问题描述】:
我有这段代码,可用于在 Excel 中使用 vba 发送电子邮件。
使用 .body 而不是 .Inspector.WordEditor 我可以准确地在电子邮件中键入我想要的内容,但我希望电子邮件的文本是包含一些图片和其他内容的 Word 文档。
我会怎么做呢?我无法让 .Inspector.WordEditor 以我想要的方式工作。 (老实说,这对我来说根本不起作用)
Sub Test1()
Dim networkstatus As Boolean
If InternetGetConnectedState(0&, 0&) Then
networkstatus = True
Else
networkstatus = False
End If
If Not networkstatus = True Then
Exit Sub
End If
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "C").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Test"
.Inspector.WordEditor ("C:\test.docx")
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
清理:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
编辑:我知道您可以使用 HTMLBody,但我不指望我的同事使用它。
【问题讨论】:
标签: vba