【问题标题】:Outlook 2010 Email body is emptyOutlook 2010 电子邮件正文为空
【发布时间】:2018-08-01 18:05:24
【问题描述】:

我在基本的 .Body 工作方面遇到了最严重的问题。我读过这个:VBA Outlook 2010 received mail .Body is empty 但它很旧,当我点击它时找不到答案中引用的另一个问题。这是我的基本代码。

Sub AutoReplyTrap(objInMail As MailItem)

Dim objOutMail As Outlook.MailItem

Dim vText As Variant
Dim sText As String
Dim strID As String
Dim sSubject As String
Dim vItem As Variant
Dim vFirstName As Variant
Dim i As Long
Dim j As Integer
Dim strSignature As String
Dim strSigString As String
Dim strFirstName As String
Dim strFirstLetter As String
Dim strEMailAddress As String
Dim blnFirstName As Boolean
Dim blnEMail As Boolean

' change the bodyformat to plain text
objInMail.BodyFormat = Outlook.OlBodyFormat.olFormatPlain

objInMail.Display

blnFirstName = False
blnEMail = False
j = 0

' believe there is a timing issue that Body may not be fully loaded.
' so I'm going to pause and loop through 20 times to see if it gets loaded.
WaitForBody:
sText = objInMail.Body
If sText = "" Then
    If j < 20 Then
        j = j + 1
        Sleep 1000
        GoTo WaitForBody
    End If
End If

If sText = "" Then
    MsgBox ("No body in email!")
    Exit Sub
End If

End Sub

如您所见,我认为可能是时间问题,所以我构建了循环来测试我是否有身体,如​​果没有,请稍等一会,然后再试 20 次。

这是有趣的部分...如果我有 objInMail.Display 它可以工作,但如果我删除该行,它将循环 20 次尝试并失败。虽然我不喜欢,但如果我可以“取消显示”它,我可能会接受显示,但我想知道 .close 是否真的会用电子邮件关闭所有内容,我会再次丢失正文。

显然,我更希望它在没有 objInMail.Display 的情况下工作。

有什么建议或建议吗?

【问题讨论】:

  • 我确实发现 .Display 之后立即关闭 objInMail.Close olDiscard 将关闭消息窗口,我确实得到了正文。如果我注释掉 .Display 或两个语句 .Display 和 .Close,则 .Body 为空。任何帮助表示赞赏。
  • 那么一旦你改变了正文格式,你想做什么?
  • @0m3r,不确定它是否有所不同,但我所做的是从传入消息中提取一些数据,使用提取的数据创建一条新消息并发送新消息。

标签: vba outlook


【解决方案1】:

如果不需要显示则:

objInMail.GetInspector

MailItem.GetInspector Property "...用于返回一个 Inspector 对象,在其中显示项目..."

我看到一个报告说行为发生了变化。 GetInspector 可能不再可靠地替换 .Display

【讨论】:

    猜你喜欢
    • 2017-07-09
    • 2020-08-15
    • 2014-12-17
    • 2012-01-22
    • 1970-01-01
    • 2013-02-11
    • 2018-10-17
    • 2014-04-17
    • 1970-01-01
    相关资源
    最近更新 更多