Office 2016中的MailItem.GetInspector.WordEditor生成应用程序定义或对象定义的错误 [英] MailItem.GetInspector.WordEditor in Office 2016 generates Application-defined or object defined error
问题描述
我写了一个Excel宏来从电子表格发送电子邮件.它可以在Office 2013上运行,但不能在Office 2016上运行.
I wrote an Excel macro to send email from a spreadsheet. It works on Office 2013, but not Office 2016.
我查看了Office 2013和2016之间的VBA差异,但是看不到有关检查器或邮件对象的文字编辑器的任何更改.
I looked at the VBA differences between Office 2013 and 2016, but couldn't see anything about changes to the inspector or word editor for message objects.
一旦到达.GetInspector.WordEditor
,它将引发:
运行时错误'287':
应用程序定义或对象定义的错误
Run-time error '287':
Application-defined or object defined error
这是宏的相关部分:
Sub SendEmail()
Dim actSheet As Worksheet
Set actSheet = ActiveSheet
'directories of attachment and email template
Dim dirEmail as String, dirAttach As String
' Directory of email template as word document
dirEmail = _
"Path_To_Word_Doc_Email_Body"
' Directories of attachments
dirAttach = _
"Path_To_Attachment"
' Email Subject line
Dim subjEmail As String
subjEmail = "Email Subject"
Dim wordApp As Word.Application
Dim docEmail As Word.Document
' Opens email template and copies it
Set wordApp = New Word.Application
Set docEmail = wordApp.Documents.Open(dirEmail, ReadOnly:=True)
docEmail.Content.Copy
Dim OutApp As Outlook.Application
Set OutApp = New Outlook.Application
Dim OutMail As MailItem
Dim outEdit As Word.Document
' The names/emails to send to
Dim docName As String, sendEmail As String, ccEmail As String, siteName As String
Dim corName As String
Dim row As Integer
For row = 2 To 20
sendName = actSheet.Cells(row, 1)
sendEmail = actSheet.Cells(row, 2)
ccEmail = actSheet.Cells(row, 3)
siteName = actSheet.Cells(row, 4)
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.SendUsingAccount = OutApp.Session.Accounts.Item(1)
.To = sendEmail
.CC = ccEmail
.Subject = subjEmail & " (Site: " & siteName & ")"
Set outEdit = .GetInspector.WordEditor
outEdit.Content.Paste
outEdit.Range(0).InsertBefore ("Dear " & sendName & "," & vbNewLine)
.Attachments.Add dirAttach
.Display
'.Send
End With
Debug.Print row
Set OutMail = Nothing
Set outEdit = Nothing
Next row
docEmail.Close False
wordApp.Quit
End Sub
我根据建议尝试过的事情:
Things I've tried based on suggestions:
- 已检查的Outlook设置-默认为HTML文本
- 将
.display
移动到.GetInspector.WordEditor
- Checked Outlook settings - default is HTML text
- Moved
.display
over.GetInspector.WordEditor
推荐答案
确保Word是默认的电子邮件编辑器.从 Inspector.WordEditor dox :
Ensure Word is the default email editor. From the Inspector.WordEditor dox:
仅当
IsWordMail
方法返回True且EditorType
属性为olEditorWord
时,WordEditor
属性才有效.返回的WordDocument
对象提供对大多数Word对象模型的访问权限...
The
WordEditor
property is only valid if theIsWordMail
method returns True and theEditorType
property isolEditorWord
. The returnedWordDocument
object provides access to most of the Word object model...
此外,确保将Outlook配置为发送RTF或HTML电子邮件,而不是纯文本.
Further, ensure that Outlook is configured to send Rich Text or HTML emails, not plain text.
这篇关于Office 2016中的MailItem.GetInspector.WordEditor生成应用程序定义或对象定义的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!