英文:
Reply to mail item with a post item using VBA
问题
I understand that you want a translation of the provided text. Here's the translation:
"我想要回复收件箱中的邮件项,将其转为帖子项。您可以通过以下方式看到我想要复制的精确行为:
- 在活动资源管理器中选择一封电子邮件消息。
- 单击“Ctrl + T”。
- 添加文本到帖子中。
- 单击“发布”。
生成的帖子项包含被回复的电子邮件消息的电子邮件正文,添加的文本(#3),并且还继承了电子邮件消息的conversationID属性,因此它会出现在对话中。
出于某种原因,我无法在VBA中实现这一点。
以下是我尝试过的内容:
Sub ReplyToMessage()
' 声明变量
Dim objItem As Outlook.MailItem
Dim objReply As Outlook.MailItem
' 获取选定的消息
Set objItem = Application.ActiveExplorer.Selection.Item(1)
' 创建回复消息
Set objReply = objItem.Reply
' 将消息类别设置为olPostItem
objReply.MessageClass = "IPM.Post" ' 这会导致错误
' 向回复消息添加文本
objReply.Body = "在这里添加您的回复消息。"
' 显示回复消息
objReply.Display
End Sub
但以上代码仅创建了一封电子邮件回复,而不是帖子。我还尝试创建一个新的帖子项并复制正文、主题等,但采用这种方法时,帖子不会继承我回复的消息的conversationID,这是至关重要的。我还尝试使用sendkeys发送“^n”,但该代码运行时没有任何反应 - Outlook没有任何响应。
简单总结这个问题的最简单方式是:如何编写VBA以复制在活动资源管理器中选择邮件项并按“Ctrl + T”时发生的情况,创建一个帖子项,以便在对话中回复邮件项?我正在运行Microsoft Office Professional Plus 2016(16.0.5387.1000),它是64位版本。"
英文:
I would like to reply to a mailitem in my inbox with a postitem. You can see the precise behavior I'm looking to replicate by:
-
Selecting an email message in the active explorer
-
Clicking "ctrl + T"
-
Adding text to the post
-
Clicking "post"
The resulting postitem contains the e-mail body of the email message replied to, the added text (#3 above) and also takes on the e-mail message's conversationID property, so it appears within the conversation.
For some reason, I can't achieve this in VBA.
Here's what I've tried:
Sub ReplyToMessage()
' Declare Variables
Dim objItem As Outlook.MailItem
Dim objReply As Outlook.MailItem
' Get the selected message
Set objItem = Application.ActiveExplorer.Selection.Item(1)
' Create a reply message
Set objReply = objItem.Reply
' Set the message class to olPostItem
objReply.MessageClass = "IPM.Post" ' this errors out as
' Add text to the reply message
objReply.Body = "Your reply message goes here."
' Display the reply message
objReply.Display
End Sub
But the above merely creates an e-mail reply, not a post. I've also tried creating a new post item and copying the body, subject, etc, but when taking that approach, the post doesn't take on the conversationID of the message I'm replying to, which is critical. I've also tried using sendkeys to send "^n", but that code runs without doing anything - no response whatsoever from outlook.
The simplest way to summarize this problem is: How can I write VBA to replicate what is occuring when "ctrl + T" is pressed with a mailitem selected in the active explorer, creating a postitem that replies in-conversation to a mailitem? I am running Microsoft Office Professional Plus 2016 (16.0.5387.1000) and it is 64 bit.
答案1
得分: 1
你需要说服Outlook忘记关于那个项目的事项。
Set objReply = objItem.Reply
objReply.Body = "您的回复消息在此处。" & vbCrLf & objReply.Body
' 设置消息类别为olPostItem
objReply.MessageClass = "IPM.Post"
objReply.Save
entryId = objReply.EntryID
' 重新打开为PostItem
Set objReply = Nothing
Set objReply = Application.Session.GetItemFromID(entryId)
objReply.Display
英文:
You need to convince Outlook to forget about that item
Set objReply = objItem.Reply
objReply.Body = "Your reply message goes here." & vbCrLf & objReply.Body
' Set the message class to olPostItem
objReply.MessageClass = "IPM.Post"
objReply.Save
entryId = objReply.EntryID
'reopen as PostItem
set objReply = Nothing
set objReply = Application.Session.GetItemFromID(entryId)
objReply.Display
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论