VBA Outlook 2010收到邮件.正文为空 [英] VBA Outlook 2010 received mail .Body is empty

查看:121
本文介绍了VBA Outlook 2010收到邮件.正文为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Outlook VBA中编写一个脚本,以将每一封电子邮件进入我的收件箱时记录在Access数据库中.我有没有触发的代码.它可以毫无问题地访问Access数据库.它毫无问题地复制了主题.然后它到达身体,什么也没复制.我尝试了诸如.HTMLbody之类的方法,而不仅仅是.Body,但这再次显示了一个空的正文.我的代码如下:

I am writing a script in Outlook VBA to record every email in an Access database as they come in to my inbox. The code I have triggers with no issue. It accesses the Access database with no issue. It copies the subject across with no issue. Then it gets to the body and copies nothing at all. I have tried things like .HTMLbody instead of just .Body, but this again shows an empty body. My code is as follows:

Option Explicit
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim objNS As Outlook.NameSpace
Dim objEmail As Outlook.MailItem
Dim strIDs() As String
Dim intX As Integer
Dim ws As DAO.Workspace
Dim db As DAO.Database
Dim sDb As String
Dim sSQL As String
Dim qdf As QueryDef
strIDs = Split(EntryIDCollection, ",")
For intX = 0 To UBound(strIDs)
Set objNS = Application.GetNamespace("MAPI")
Set objEmail = objNS.GetItemFromID(strIDs(intX))
    sDb = "C:\Users\######\Documents\EmailDatabase.accdb"
    Set ws = DBEngine.Workspaces(0)
    Set db = ws.OpenDatabase(sDb)
    sSQL = "INSERT INTO AllEmails (Subject,Message) Values ('" & objEmail.Subject & "','" & objEmail.HTMLBody & "')"
    Set qdf = db.CreateQueryDef("", sSQL)
    qdf.Execute dbFailOnErro
MsgBox objEmail.HTMLBody
Next
Set objEmail = Nothing
End Sub

如果有人知道我在做什么错,请告诉我.三个小时的谷歌搜索似乎还没有完成!

If anyone has any idea what I am doing wrong please do let me know. Three hours of googling doesn't seem to have sorted it!

推荐答案

感谢LEBoyd,现在已经解决了这个问题!解决方案是先显示该消息,然后立即关闭olDiscard.由于某些尚待解释的原因,它充满了身体.请在此处查看LEBoyd的问题- Outlook 2010电子邮件正文为空

This question has now been resolved thanks to LEBoyd! The solution is to .display the message and then immediately .close olDiscard. For some yet-to-be-explained reason, it fills the body. See LEBoyd's question here - Outlook 2010 Email body is empty

这篇关于VBA Outlook 2010收到邮件.正文为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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