VBA Excel图片粘贴在Outlook邮件中的文本

问题描述:

我是vba编码新手,我遇到了我的宏问题。我试图将Excel中的范围复制到Outlook邮件中,并在主体中添加文本。但是,我的代码添加了文本,然后将图片粘贴到上面。我怎样才能得到它粘贴在文本下?VBA Excel图片粘贴在Outlook邮件中的文本

这里是我的代码:

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 = "[email protected]" 
    .CC = "[email protected]" 
    .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 

你与你的图片替换消息的Word文档的整个范围。相反,你需要注意你想要粘贴的范围。这应该把它放在你的文字后面:

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

它的工作原理!谢谢 –