VBA将Excel范围转换为图片并发送到Outlook,将文本写入正文 [英] Vba convert Excel range into picture and send to Outlook, write text into body

查看:597
本文介绍了VBA将Excel范围转换为图片并发送到Outlook,将文本写入正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从受保护的Excel工作表中复制一个范围,并将其作为图片粘贴到Outlook中,编写一些文本并显示它.

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.

下面的代码首先粘贴文本,然后粘贴图片,但同时删除文本.但是我想要文本和文本下面的图片(范围从Excel转换为图片).

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

推荐答案

从这一行开始

Set Email = OutMail.GetInspector.WordEditor

这应该做到:

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

这篇关于VBA将Excel范围转换为图片并发送到Outlook,将文本写入正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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