将Excel范围粘贴为图像

时间:2018-03-27 19:40:16

标签: excel vba excel-vba outlook outlook-vba

我尝试将多个Excel范围粘贴为Outlook正文上的图像。

我有这段代码可以使用,但是当我粘贴图片时,它会删除我已经在电子邮件正文中写的.HTMLBody

如何保持HTMLBody粘贴图像。

Dim r As Range
Set r = Range("A1:U49")
r.Copy

'Open a new mail item
Dim outlookApp As Outlook.Application
Set outlookApp = CreateObject("Outlook.Application")
Dim outMail As Outlook.MailItem
Set outMail = outlookApp.CreateItem(olMailItem)
Dim wordDoc As Word.Document
Set wordDoc = outMail.GetInspector.WordEditor

'Get its Word editor

With outMail
    .display
    .HTMLBody = "<p>Boa tarde,</p>" & _
    "<p>Segue abaixo para acompanhamento <strong>gerencial</strong> dos ritmos de opera&ccedil;&otilde;es.</p>" & _
    "<p>Essa visibilidade di&aacute;ria &eacute; importante para medir como estamos em rela&ccedil;&atilde;o ao plano (IBP-S&amp;OP) e a capacidade informada.</p>" & _
    "<p><em>LEGENDA </em></p>"

End With

wordDoc.Range.PasteAndFormat wdChartPicture

1 个答案:

答案 0 :(得分:0)

问题是您将htmlbody替换为wordDoc.Range.PasteAndFormat wdChartPicture

您的HTMLBody看起来有多个段落,因此使用 Paragraphs Object (Word) Paragraphs属性会返回Paragraphs集合Paragraphs(1)或{{ 1}}等等然后决定放置图像的位置。

实施例

(2)

通过使用段落集合,您将使用当前wordDoc.Paragraphs(1).Range.PasteAndFormat wdChartPicture 并保留您的签名等...