excel - 如何创建 Outlook 电子邮件并调整所有图像的大小
问题描述
下面的 Excel 宏效果很好,除了粘贴到正文中的 Excel 范围内的图像会调整大小(其中大部分为 55%)。
我不知道出了什么问题。
如果我手动复制完全相同的范围并将其粘贴到电子邮件中,图像将保持不变。
Sub mailpaste()
Dim OutApp As Object
Dim OutMail As Object
Dim olInsp As Object
Dim xlSheet As Worksheet
Dim wdDoc As Object
Dim oRng As Object
Dim rngTo As Range
Dim rngSubject As Range
Application.Range("Report").copy
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
If Err <> 0 Then Set OutApp = CreateObject("Outlook.Application")
On Error GoTo 0
With ActiveSheet
Set rngTo = .Range("AA12")
Set rngSubject = .Range("AA15")
End With
Set OutMail = OutApp.CreateItem(0)
With OutMail
.BodyFormat = 2
.To = rngTo.Value
.CC = ""
.BCC = ""
.Subject = rngSubject.Value
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oRng = wdDoc.Range
oRng.collapse 1
oRng.Paste
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
Set olInsp = Nothing
Set wdDoc = Nothing
Set oRng = Nothing
End Sub
解决方案
您已经在使用 Word 对象,因此请使用内联形状的 InlineShapes 属性高度/宽度
例子
Set OutMail = OutApp.CreateItem(0)
Set wdDoc = OutMail.GetInspector.WordEditor
With OutMail
.BodyFormat = 2
.To = rngTo.Value
.CC = ""
.BCC = ""
.Subject = rngSubject.Value
.Display
wdDoc.Range.PasteAndFormat Type:=wdChartPicture
With wdDoc
.InlineShapes(1).Height = 130
.InlineShapes(1).Width = 130
End With
End With
推荐阅读
- java - JMeter 从路径参数的开头删除正斜杠
- android - 使用 Retrofit 和 GsonConverterFactory 将 JsonArray 转换为 Kotlin 数据类(预期为 BEGIN_OBJECT 但为 BEGIN_ARRAY)
- firefox - 如何实现对 Firefox 48 及更高版本的 Protractor 支持?
- python - 使用标准标记进行 2D 彩色绘图的替代方法?
- excel - 通过用户表单查找具有特定值的行并复制/粘贴到另一张表
- sql - SQL SELECT 如何在两列之间查找子字符串编号?
- python-3.x - 如何从 .h5 文件正确加载带有自定义层的 Keras 模型?
- java - 用硒停用铬警报
- c# - 如何订阅泛型类的静态事件
- android - 我们可以检测手机是否有前置电动摄像头吗?