【问题标题】:Adding .docx as body to Outlook e-mail in VBA在 VBA 中将 .docx 作为正文添加到 Outlook 电子邮件
【发布时间】: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


    【解决方案1】:

    将其作为附件发送

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

    【讨论】:

    • 但我希望它进入电子邮件正文。这是一份时事通讯。
    • 你需要将它保存为 HTML,Word 可以做到这一点。然后将 HTML 读入电子邮件正文。但是,请记住,大多数现代电子邮件提供商默认禁用图片。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-15
    • 1970-01-01
    相关资源
    最近更新 更多