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

查看:31
本文介绍了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######DocumentsEmailDatabase.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,这个问题现已得到解决!解决方案是 .display 消息,然后立即 .close 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天全站免登陆