图片使用Excel VBA粘贴到Outlook邮件中的文本上 [英] Picture pastes over text in Outlook mail using Excel VBA

查看:1063
本文介绍了图片使用Excel VBA粘贴到Outlook邮件中的文本上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Excel中的范围作为图片复制到Outlook邮件中,并在正文中也添加文本.

I'm trying to copy a range in Excel as a picture to Outlook mail and add text in the body as well.

我的代码是添加文本,然后将图片粘贴在其顶部.如何将其粘贴到文本下方?

My code is adding the text and then pasting the picture on top of it. How can I get it to paste under the text?

Dim OutApp As Object
Dim outMail As Object
Dim myFileList(1) As String
Dim i As Long

Set OutApp = CreateObject("Outlook.Application")
Set outMail = OutApp.CreateItem(0)

Set RngCopied = Worksheets("Daily volume summary").Range("VolumeRange")

myFileList(0) = "Y:xyz\sales.pdf"
myFileList(1) = "Y:xyz\sales.xlsx"

'On Error Resume Next
With outMail
    .To = "abc@xyz.com"
    .CC = "def@xyz.com"
    .BCC = ""
    .Subject = "PBC Daily Sales  " & Format(Date, "mm/dd/yyyy")
    .Body = "Good morning," & vbNewLine & vbNewLine & "Attach is the Daily Sales report for  " & Format(Date, "dddd,mmmm,dd,YYYY") & "." & "<br>" 

    'Copy range of interest

    Dim r As Range

    Set r = Worksheets("Daily volume summary").Range("VolumeRange") 
    r.Copy

    'Get its Word editor 
    outMail.Display
    Dim wordDoc As Word.Document
    Set wordDoc = outMail.GetInspector.WordEditor

    'To paste as picture
    wordDoc.Range.PasteAndFormat wdChartPicture
    Dim shp As Object
    For Each shp In wordDoc.InlineShapes
        shp.ScaleHeight = 60
        shp.ScaleWidth = 60
    Next

    For i = 0 To UBound(myFileList)
        .Attachments.Add myFileList(i)
    Next

    .Send
End With
On Error GoTo 0

Set outMail = Nothing
Set OutApp = Nothing
End Sub

推荐答案

在此行:

 wordDoc.Range.PasteAndFormat wdChartPicture

您正在用图片替换消息的单词doc的整个范围.相反,您需要注意要将其粘贴在范围内的哪个位置.这应该放在您的文字之后:

you are replacing the ENTIRE range of the message's word doc with your picture. Instead you need to note where in the range you want to paste this. This should put it after your text:

 wordDoc.Range(start:=wordDoc.Range.End - 2).PasteAndFormat wdChartPicture

这篇关于图片使用Excel VBA粘贴到Outlook邮件中的文本上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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