添加文字和Excel表格作为图片发送到电子邮件 [英] Add Text & Excel table as picture to email

查看:133
本文介绍了添加文字和Excel表格作为图片发送到电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何同时添加文字和将Excel表(作为图片)发送到Outlook邮件?

How do I add both text & Excel table (as a picture) to Outlook mail?

我不想使用RangetoHTML1函数,因为它不保存条件格式.

I don't want to use the RangetoHTML1 function since it doesn't save the conditional formatting.

在下面的代码中,表格作为图片复制到邮件中.如何添加文字?

In the code below, the table is copied as picture to the mail. How do I add the text?

Sub SendCA_list()
    Dim oApp As Object, oMail As Object, rng As Range, p As Picture
    Dim strBody As String, wordDoc As Object

    Set oApp = CreateObject("Outlook.Application")
    Set oMail = oApp.CreateItem(olMailItem)
    Set rng = Range("Table4[[#All],[Department]:[Status]]")
    rng.Copy  'copy required table
    Set p = ActiveSheet.Pictures.Paste 'paste and cut the table to make picture
    p.Cut

    With oMail
        .Subject = "Request for CAs - ISO Audit"
        strBody = "<BODY style='font-size:12pt;font-family:HP Simplified'>" & _
            "Hi,<br><br>Please see attached report and the open " & _
            "AIs (itable below).<br><br>Best Regards,<br>Shira" & "</BODY>"
        .HTMLBody = strBody
        Set wordDoc = oMail.GetInspector.WordEditor
        wordDoc.Range.Paste
        .Display
    End With
End Sub

推荐答案

好,这是另一种解决问题的方法,该问题是导出图像,然后使用HTML引用附加的图像.

Ok, this is another way to approach the problem which exports the image and then attaches in with the HTML referring to the attached image.

Sub SendCA_list()

    Dim oApp As Object
    Set oApp = CreateObject("Outlook.Application")

    Dim oMail As Object
    Set oMail = oApp.CreateItem(0)

    Dim rng As Range
    Set rng = Sheet1.Range("Table4[[#All],[Department]:[Status]]")
    rng.CopyPicture xlPrinter

    Dim chartObj As ChartObject
    Set chartObj = Sheet1.ChartObjects.Add(0, 0, rng.Width, rng.Height)

    chartObj.Select
    chartObj.Chart.Paste
    chartObj.Chart.Export ThisWorkbook.Path & "\table.png", "png"
    chartObj.Delete

    Dim strbody As String
    strbody = "<BODY style='font-size:12pt;font-family:HP Simplified'>" & "Hi,<br><br>Please see attached the ISO Internal Audit Report and the open AIs (in the table below)."
    strbody = strbody & "<br><img src='cid:table.png'/>"
    strbody = strbody & "<br><br>Best Regards,<br>Shira<br><br></BODY>"

    With oMail

        .Subject = "Request for CAs - ISO Audit"
        .Attachments.Add ThisWorkbook.Path & "\table.png", 1, 0
        .htmlbody = strbody
        .Display
    End With
End Sub

这篇关于添加文字和Excel表格作为图片发送到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆