You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VBA生成的Outlook邮件中设置Excel区域截图的尺寸与环绕格式

实现代码

你需要操作Word编辑器内粘贴生成的图片对象完成属性设置,修改后的完整VBA代码如下:

Sub email()
    Dim ol As Object 'Outlook.Application
    Dim olEmail As Object 'Outlook.MailItem
    Dim olInsp As Object 'Outlook.Inspector
    Dim wd As Object 'Word.Document
    Dim pastedPic As Object 'Word.InlineShape
    Dim floatedPic As Object 'Word.Shape

    Sheets("Daily message").Range("B3:L21").SpecialCells(xlCellTypeVisible).Copy

    Set ol = GetObject(, "Outlook.Application")
    Set olEmail = ol.CreateItem(0) 'olMailItem

    With olEmail
        Set olInsp = .GetInspector
        If olInsp.EditorType = 4 Then 'olEditorWord
            Set wd = olInsp.WordEditor
            ' 粘贴为图片
            wd.Range.PasteAndFormat 13 'wdChartPicture
            ' 获取刚粘贴的嵌入式图片
            Set pastedPic = wd.InlineShapes(wd.InlineShapes.Count)
            ' 转换为浮动形状,设置方形环绕
            Set floatedPic = pastedPic.ConvertToShape
            floatedPic.WrapFormat.Type = 3 'wdWrapSquare 对应方形环绕
            ' 单位转换:1厘米=28.35磅,设置指定尺寸
            floatedPic.Height = 9 * 28.35
            floatedPic.Width = 28 * 28.35
        End If
        .To = "my email"
        .BCC = ""
        .Subject = "Daily message"
        .Display
    End With
End Sub
说明

你之前使用.style.width报错是因为该属性是HTML元素的样式属性,而Outlook启用Word编辑器时,需要使用Word的COM对象模型操作元素,直接修改形状对象的尺寸和环绕属性即可。


内容的提问来源于stack exchange,提问作者nattymcpatty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 08:06:03