英文:
How do I adjust the size of the pasted image in Outlook email?
问题
在网站上查看旧问题时,我找到了所需的代码,但我需要调整电子邮件中粘贴的图像的大小(高度和宽度),但我没有成功。你能帮助我吗?
Sub SendEmail()
'打开一个新邮件项
Set outlookApp = CreateObject("Outlook.Application")
Set OutMail = outlookApp.CreateItem(olMailItem)
With OutMail
.To = ""
.Subject = "** 请在上午10:30之前确认工时表 **"
.Importance = olImportanceHigh
.Display
End With
'获取其Word编辑器
Set wordDoc = OutMail.GetInspector.WordEditor
'以图片方式粘贴
rng.Copy
wordDoc.Range.PasteSpecial , , , , wdPasteBitmap
OutMail.HTMLBody = "Timesheets Submitted by " & "Marco" & "<br>" & _
vbNewLine & OutMail.HTMLBody
End Sub
我尝试创建一些命令来调整图像大小,但没有成功。
英文:
Looking at old questions here on the site I found the code I needed, but I need to adjust the size (height and width) of the image pasted in the email, but I was unsuccessful. Can you help me?
Sub SendEmail()
'Open a new mail item
Set outlookApp = CreateObject("Outlook.Application")
Set OutMail = outlookApp.CreateItem(olMailItem)
With OutMail
.To = ""
.Subject = "** Please confirm Timesheet by 10:30AM **"
.Importance = olImportanceHigh
.Display
End With
'Get its Word editor
Set wordDoc = OutMail.GetInspector.WordEditor
'To paste as picture
rng.Copy
wordDoc.Range.PasteSpecial , , , , wdPasteBitmap
OutMail.HTMLBody = "Timesheets Submitted by " & "Marco" & "<br>" & _
vbNewLine & OutMail.HTMLBody
End Sub
I tried to create some command to resize image size but without success.
答案1
得分: 2
这是你正在尝试的吗?我已经对代码进行了注释,但如果你遇到困难,可以随时问。
选项 显式
'~~> 由于我们使用的是后期绑定
'~~> Outlook 常量
Private Const olImportanceHigh = 2
Private Const olMailItem = 0
'~~> Word 常量
Private Const wdChartPicture = 13
Sub 发送邮件()
'~~> 工作表操作
Dim ws As 工作表
Dim rng As 范围
Dim pic As 图片
'~~> 将此更改为相关工作表
Set ws = Sheet1
'~~> 将此更改为相关范围
Set rng = ws.Range("A1:A15")
'~~> 复制范围并将其粘贴到图片对象中
rng.Copy
Set pic = ws.Pictures.Paste
'~~> 在此设置尺寸
With pic.ShapeRange
.LockAspectRatio = msoTrue
.Height = 200
.Width = 200
End With
'~~> Outlook 操作
Dim OutApp As 对象
Dim OutMail As 对象
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ""
.Subject = "** 请在上午10:30之前确认时间表 **"
.Importance = olImportanceHigh
.Display
End With
Dim wordDoc As 对象
Set wordDoc = OutMail.GetInspector.WordEditor
'~~> 剪切图片并粘贴到电子邮件中
pic.Cut
DoEvents
wordDoc.Range.pasteandformat wdChartPicture
OutMail.HTMLBody = "Marco提交的时间表" & _
"<br>" & OutMail.HTMLBody
End Sub
**一个重要的提示**:始终声明并使用对象/变量。这将让你的生活更轻松...
英文:
Is this what you are trying? I have commented the code but if you get stuck then simply ask.
Option Explicit
'~~> Since we are working using Late Binding
'~~> Outlook Constants
Private Const olImportanceHigh = 2
Private Const olMailItem = 0
'~~> Word Constant
Private Const wdChartPicture = 13
Sub SendEmail()
'~~> Worksheet Operations
Dim ws As Worksheet
Dim rng As Range
Dim pic As Picture
'~~> Change this to the relevant sheet
Set ws = Sheet1
'~~> Change this to the relevant range
Set rng = ws.Range("A1:A15")
'~~> Copy the range and paste it in a picture object
rng.Copy
Set pic = ws.Pictures.Paste
'~~> Set the dimensions here
With pic.ShapeRange
.LockAspectRatio = msoTrue
.Height = 200
.Width = 200
End With
'~~> Outlook Operations
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ""
.Subject = "** Please confirm Timesheet by 10:30AM **"
.Importance = olImportanceHigh
.Display
End With
Dim wordDoc As Object
Set wordDoc = OutMail.GetInspector.WordEditor
'~~> Cut the picture and paste in email
pic.Cut
DoEvents
wordDoc.Range.pasteandformat wdChartPicture
OutMail.HTMLBody = "Timesheets Submitted by Marco" & _
"<br>" & _
vbNewLine & OutMail.HTMLBody
End Sub
One important tip: Always declare and work with Objects/Variables. Will make your life easier...
答案2
得分: 1
使用Word对象模型粘贴内容后,您可以通过指定img
元素的height
和width
来编辑生成的HTML标记。
或者只需使用Siddharth建议的Range.PasteAndFormat方法。
英文:
After using the Word object model for pasting the content you can edit the resulted HTML markup by specifying the height
and width
for the img
element.
Or just use the Range.PasteAndFormat method which Siddharth suggested.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论