在VBA中发送Outlook电子邮件,任何冒号“:”的主题都会导致电子邮件空白

我有一个复制word文档内容的macros,将其粘贴到电子邮件中。 然后从Excel中提取电子邮件地址和姓名,并向每个人发送附件的电子邮件。 (本质上是一个邮件合并)

问题是,任何时候,主题有冒号“:”,电子邮件发送为空白。 这不会发生,如果我保存电子邮件,也不会显示它。 只有立即发送才会发生。

这里是代码:

Option Explicit Sub SendInitialEmail() 'directory of email body Dim dirEmailBody As String ' Directory of email template dirEmailBody = _ "C:\Users\me\Documents\Email Body.docx" Dim wordApp As Word.Application Dim docEmail As Document ' Opens email template and copies it Set wordApp = New Word.Application Set docEmail = wordApp.Documents.Open(dirEmailBody) docEmail.Content.Copy Dim outEdit As Document Dim outApp As Outlook.Application Set outApp = New Outlook.Application Dim outMail As MailItem ' The names/emails to send too Dim sendName As String, sendEmail As String, _ ccEmail As String, siteName As String Dim row As Integer ' Was only testing on one row, but generally this pulls from 'a sheet of names and email addresses to send an email with attachments too. For row = 1 to 1 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 = "myemailaddress to test@gmail.com" .BodyFormat = olFormatHTML .subject = _ "Is the error cause of a colon: Email test to me" ' it was Set outEdit = .GetInspector.WordEditor outEdit.Content.Paste outEdit.Range(0).InsertBefore ("Dear " & sendName & "," & vbNewLine) ' If I do display, it shows up correctly. ' If I display then send it is fine (workaround) .Send End With Next row docEmail.Close wordApp.Quit End Sub 

删除以下内容:

Set outEdit = .GetInspector.WordEditor outEdit.Content.Paste outEdit.Range(0).InsertBefore ("Dear " & sendName & "," & vbNewLine)

并添加:

 `.Body = "Dear " & sendName & "," & vbNewLine & docEmail.Content.Text` 

冒号不是问题。

尝试使用Chr()命令,在这种情况下,“:”是Chr(58)