运行时错误 287 - 设置 inspector.wordeditor 时的 Outlook [英] run-time error 287 - Outlook when set inspector.wordeditor

查看:68
本文介绍了运行时错误 287 - 设置 inspector.wordeditor 时的 Outlook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Set oApp = CreateObject("Outlook.Application")

Set oMailItem = oApp.CreateItem(0)

oMailItem.BodyFormat = olFormatRichText

Set oInspector = oMailItem.GetInspector

oInspector.Display


MsgBox "IsWordMail = " & oInspector.IsWordMail & vbLf & "EditorType = " & (oInspector.EditorType = olEditorWord) ' Both are true.

Set wdDoc = oInspector.WordEditor '<--运行时错误 '287' Appication-Defined or Object-Defined Error

Set wdDoc = oInspector.WordEditor '<--Run-time error '287' Appication-Defined or Object-Defined Error

option-mail-composer 消息格式为HTML"Outlook 参考 16.0 设置

option-mail- composer message in this format is "HTML" outlook reference 16.0 is set up

推荐答案

如果代码在迁移到 Office 365 后突然停止工作或由于任何其他原因,请参考下面的代码.已添加注释以便于理解和实施.

If the code suddenly stopped working after migrating to Office 365 or for any other reasons, please refer to the code below. Comments have been added for easy understanding and implementation.

如果您拥有管理权限,那么您还可以尝试以下链接中给出的注册表更改:https://support.microsoft.com/en-au/help/926512/information-for-administrators-about-e-mail-security-settings-in-outlo

If you have administrative rights then you can also try the registry changes given at below link: https://support.microsoft.com/en-au/help/926512/information-for-administrators-about-e-mail-security-settings-in-outlo

但是,我建议使用 Excel 版本的代码,无需进行系统更改,因为每个最终用户的计算机也需要进行系统更改.

However, I recommend a code that's Excel version independent of making system changes because system changes will be required on each end user's machine as well.

Option Explicit

Sub Create_Email(ByVal strTo As String, ByVal strSubject As String)


    Dim rngToPicture As Range
    Dim outlookApp As Object
    Dim Outmail As Object
    Dim strTempFilePath As String
    Dim strTempFileName As String

    'Name it anything, doesn't matter
    strTempFileName = "RangeAsPNG"

    'rngToPicture is defined as NAMED RANGE in the workbook, do modify this name before use
    Set rngToPicture = Range("rngToPicture")
    Set outlookApp = CreateObject("Outlook.Application")
    Set Outmail = outlookApp.CreateItem(olMailItem)

    'Create an email
    With Outmail
        .To = strTo
        .Subject = strSubject

        'Create the range as a PNG file and store it in temp folder
        Call createPNG(rngToPicture, strTempFileName)

        'Embed the image in Outlook
        strTempFilePath = Environ$("temp") & "\" & strTempFileName & ".png"
        .Attachments.Add strTempFilePath, olByValue, 0

        'Change the HTML below to add Header (Dear John) or signature (Kind Regards) using newline tag (<br />)
        .HTMLBody = "<img src='cid:DashboardFile.png' style='border:0'>"


        .Display

    End With

    Set Outmail = Nothing
    Set outlookApp = Nothing
    Set rngToPicture = Nothing

End Sub

Sub createPNG(ByRef rngToPicture As Range, nameFile As String)

    Dim wksName As String

    wksName = rngToPicture.Parent.Name

    'Delete the existing PNG file of same name, if exists
    On Error Resume Next
        Kill Environ$("temp") & "\" & nameFile & ".png"
    On Error GoTo 0

    'Copy the range as picture
    rngToPicture.CopyPicture

    'Paste the picture in Chart area of same dimensions
    With ThisWorkbook.Worksheets(wksName).ChartObjects.Add(rngToPicture.Left, rngToPicture.Top, rngToPicture.Width, rngToPicture.Height)
        .Activate
        .Chart.Paste
        'Export the chart as PNG File to Temp folder
        .Chart.Export Environ$("temp") & "\" & nameFile & ".png", "PNG"
    End With
    Worksheets(wksName).ChartObjects(Worksheets(wksName).ChartObjects.Count).Delete

End Sub

这篇关于运行时错误 287 - 设置 inspector.wordeditor 时的 Outlook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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