Vba convert Excel range into picture and send to Outlook, write text into body

心已入冬 提交于 2019-12-23 05:00:31

问题


I would like to copy a range from protected Excel sheet and paste it into Outlook as a Picture, write some text and display it.

My code below is pasting the text first of all, and then the Picture, but at the same time deleting the text. But I want both, text and under text the picture (range converted into a picture from Excel).

Can anybody help me how to get it?

Sub Send_Email()

   Dim r As Range
   Set r = Range("NR7:OD39")

   Dim outlookApp As Outlook.Application
   Set outlookApp = CreateObject("Outlook.Application")

   Dim OutMail As Outlook.MailItem
   Set OutMail = outlookApp.CreateItem(olMailItem)

   Dim StrFileName As String

   Application.DisplayAlerts = False
   Application.ScreenUpdating = False

   Sheets("table1").Select
   ActiveSheet.Unprotect Password:="blabla"

   ActiveSheet.Outline.ShowLevels RowLevels:=8, ColumnLevels:=8

   r.Select
   r.Copy

   OutMail.Display

   Dim Email As Word.Document
   Set Email = OutMail.GetInspector.WordEditor

   With OutMail

      .To = "Name.surname@amazon.com"
      .CC = "Surname.Name@amazon.com"
      .Subject = "Subject"
      .Body = "Hi everybody," & vbNewLine & "actual Status"
      .Display

   End With

   Email.Range.PasteAndFormat wdChartPicture

   ActiveSheet.Outline.ShowLevels RowLevels:=1, ColumnLevels:=1
   ActiveSheet.Protect Password:="blabla"

End Sub

回答1:


Starting with this line

Set Email = OutMail.GetInspector.WordEditor

this should do it:

Dim ran as Word.Range
    Set Email = OutMail.GetInspector.WordEditor

       With OutMail

          .To = "Name.surname@amazon.com"
          .cc = "Surname.Name@amazon.com"
          .Subject = "Subject"
          .Body = "Hi everybody," & vbNewLine & "actual Status"
          .Display

       End With
    Email.Range.InsertAfter vbCrLf
    Set ran = Email.Range(Email.Content.End - 1, Email.Content.End - 1)
    ran.PasteAndFormat wdChartPicture


来源:https://stackoverflow.com/questions/42787663/vba-convert-excel-range-into-picture-and-send-to-outlook-write-text-into-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!