gpt4 book ai didi

vba - 运行时错误 287 - 设置 inspector.wordeditor 时的 Outlook

转载 作者:行者123 更新时间:2023-12-05 07:41:52 26 4
gpt4 key购买 nike

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 '<--Run-time error '287' Appication-Defined or Object-Defined Error

option-mail-composer message in this format is "HTML"outlook reference 16.0设置完毕

最佳答案

如果迁移到 Office 365 后代码突然停止工作或由于任何其他原因,请引用下面的代码。添加了注释以便于理解和实现。

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

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


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

关于vba - 运行时错误 287 - 设置 inspector.wordeditor 时的 Outlook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45003214/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com