excel 如何调整Outlook电子邮件中粘贴图像的大小?

olqngx59  于 2023-03-04  发布在  其他
关注(0)|答案(2)|浏览(265)

看旧问题在这里的网站上我找到了我需要的代码,但我需要调整大小(高度和宽度)的图像粘贴在电子邮件中,但我没有成功。你能帮助我吗?

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

我试图创建一些命令来调整图像大小,但没有成功。

vfwfrxfs

vfwfrxfs1#

这是你正在尝试的吗?我已经对代码进行了注解,但如果你卡住了,那就简单地问一下。

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

一个重要提示:总是声明和使用对象/变量。将使你的生活更容易...

yc0p9oo0

yc0p9oo02#

使用Word对象模型粘贴内容后,可以通过为img元素指定heightwidth来编辑生成的HTML标记。
或者使用Siddharth建议的Range.PasteAndFormat方法。

相关问题