在VBA中将.docx作为正文添加到Outlook电子邮件中

时间:2017-06-20 12:17:04

标签: vba

我有这个代码可以用来在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,但我不指望我的同事使用它。

1 个答案:

答案 0 :(得分:0)

将其作为附件发送

.Attachments.Add("C:\test.docx")

相关问题