将电子邮件项目从一个位置移动到另一个位置后无法显示
我正在尝试将电子邮件从一个地方移动到另一个地方。
示例代码来自 此处。
代码的重要部分,用于移动邮件:
If objVariant.Class = olMail Or objVariant.Class = olMeetingRequest Then
' This is optional, but it helps me to see in the
' debug window where the macro is currently at.
Debug.Print objVariant.SentOn
' Calculate the difference in years between
' this year and the year of the mail object.
intDateDiff = DateDiff("yyyy", objVariant.SentOn, Now)
' Only process the object if it isn't this year.
If intDateDiff > 0 Then
' Calculate the name of the personal folder.
strDestFolder = "Personal Folders (" & _
Year(objVariant.SentOn) & ")"
' Retrieve a folder object for the destination folder.
Set objDestFolder = objNamespace.Folders(strDestFolder).Folders("Inbox")
' Move the object to the destination folder.
objVariant.Move objDestFolder
' Just for curiousity, I like to see the number
' of items that were moved when the macro completes.
lngMovedMailItems = lngMovedMailItems + 1
' Destroy the destination folder object.
Set objDestFolder = Nothing
End If
现在,问题是,当它移动到目标文件夹时,只有邮件标题可见,邮件正文在 MS Outlook 中为空白。
我想通过显示移动电子邮件之前和移动电子邮件之后的图像来更好地了解我正在谈论的内容。
经过进一步调查,我发现邮件大小保持不变,但 MS Outlook 无法显示正文那个消息。
当我通过拖放或复制粘贴手动移动消息时,消息仍然正常。我能够看到消息正文。
I am trying to move email from one pst to another.
Sample code from here.
The important part of the code, which moves the message:
If objVariant.Class = olMail Or objVariant.Class = olMeetingRequest Then
' This is optional, but it helps me to see in the
' debug window where the macro is currently at.
Debug.Print objVariant.SentOn
' Calculate the difference in years between
' this year and the year of the mail object.
intDateDiff = DateDiff("yyyy", objVariant.SentOn, Now)
' Only process the object if it isn't this year.
If intDateDiff > 0 Then
' Calculate the name of the personal folder.
strDestFolder = "Personal Folders (" & _
Year(objVariant.SentOn) & ")"
' Retrieve a folder object for the destination folder.
Set objDestFolder = objNamespace.Folders(strDestFolder).Folders("Inbox")
' Move the object to the destination folder.
objVariant.Move objDestFolder
' Just for curiousity, I like to see the number
' of items that were moved when the macro completes.
lngMovedMailItems = lngMovedMailItems + 1
' Destroy the destination folder object.
Set objDestFolder = Nothing
End If
Now, problem is, when it moves to the destination folder, only message headers are visible, message body comes blank in MS outlook.
I'd like to give a better idea of what I am talking about, by showing the images of before move email and after move email.
On further investigating, I found message size remain same, but MS Outlook is not able to display the body of that message.
When, I move a message manually, either via Drag and drop or copy paste, message remains fine. I am able to see Message body.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已尽可能地复制您的代码和环境。我创建了一个名为“个人文件夹 (2011)”的 PST 文件。我使用了与您的代码中相同的方法来定位目标文件夹。但我无法重复您报告的错误。我移动的消息按我的预期显示。
BodyFormatProperty 的 Microsoft Visual Basic 帮助说:
然而,我不相信这段文字。我遇到过在访问正文之前 BodyFormat 属性已损坏的情况。如果 Outlook 仅在 BodyFormat 属性具有有效值的情况下查找正文,您将出现您所描述的症状。这就是为什么我想知道(1)未损坏的正文是否确实存在于移动的消息中以及(2)以编程方式访问正文是否可以解决问题。
请运行以下宏(或类似的宏)并报告输出的性质。
对于有效的消息,这些宏将在立即窗口中输出如下所示的内容:
我希望您得到这样的输出。也就是说,我希望消息体存在且正确。我进一步希望在访问这些正文后,Outlook 可以显示它们。如果我是对的,你可以在移动尸体之前尝试接触它们。如果做不到这一点,您将需要一个例程来访问新移动的消息,但不显示。
I have duplicated your code and environment as closely as I can. I have created a PST file named "Personal Folders (2011)". I have used the same method of locating the destination folder as in your code. But I cannot duplicate the error you report. My moved messages display as I would expect.
Microsoft Visual Basic Help for BodyFormatProperty says:
However, I do not believe this text. I have encountered cases where the BodyFormat property is corrupt until the body is accessed. If Outlook only looks for the body if the BodyFormat property has a valid value, you would get the symptoms you describe. This is why I wish to know (1) if the uncorrupted body is actually present in the moved messages and (2) if accessing the bodies programmatically fixes the problem.
Please run the following macros (or something like them) and report the nature of the output.
For valid messages, these macros will output something like the following to the immediate window:
What I hope is that you get output like this. That is, I hope the message bodies are present and correct. I further hope that having accessed the bodies, Outlook can display them. If I am right, you could try accessing the bodies before moving them. Failing that, you would need a routine to access the newly moved messages but without the display.