gpt4 book ai didi

excel - 如何在带有邮件线程的 excel 中使用 vba 回复 Outlook 邮件?

转载 作者:行者123 更新时间:2023-12-04 21:46:32 25 4
gpt4 key购买 nike

我正在寻找 excel 中的 VBA 代码来回复选定的邮件,但下面的代码会创建单独的邮件,该邮件在正文中的对话(线程)中没有以前的消息。我在网上搜索,但其中大多数是目前无法使用的旧代码。请帮忙。

Sub Test_template()

Dim emailApplication As Object
Dim emailItem As Object

Set emailApplication = CreateObject("Outlook.Application")
Set emailItem = emailApplication.ActiveExplorer.Selection.Item(1).ReplyAll

emailItem.bcc = "XYZ.com"

emailItem.Body = "Hi, have a nice day "

emailItem.Display

Set emailItem = Nothing
Set emailApplication = Nothing

End Sub

最佳答案

这是你正在尝试的吗?我已经评论了代码并提供了相关的 MSDN 链接。如果您仍然卡住,那么只需询问即可。

Option Explicit

Sub Sample()
Dim OutlookApp As Object
Dim OutlookMail As Object

Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.ActiveExplorer.Selection.Item(1)

'~~> Get MailItem.GetConversation method (Outlook)
' https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem.getconversation
Dim OutlookConversation As Object
Set OutlookConversation = OutlookMail.GetConversation

'~~> Conversation.GetTable method (Outlook)
' https://docs.microsoft.com/en-us/office/vba/api/outlook.conversation.gettable
Dim OutlookTable As Object
Set OutlookTable = OutlookConversation.GetTable

'~~> Obtains a 2D array from the Table.
' https://docs.microsoft.com/en-us/office/vba/api/outlook.table.getarray
Dim OutlookAr As Variant
OutlookAr = OutlookTable.GetArray(OutlookTable.GetRowCount)

Dim OutlookReplyToThisMail As Object
Set OutlookReplyToThisMail = OutlookMail.Session.GetItemFromID(OutlookAr(UBound(OutlookAr), 0))

Dim MyMessage As String: MyMessage = "Hi, have a nice day "

With OutlookReplyToThisMail.ReplyAll
.BCC = "XYZ.com"
.HTMLBody = MyMessage & .HTMLBody
.Display
End With
End Sub

关于excel - 如何在带有邮件线程的 excel 中使用 vba 回复 Outlook 邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64058977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com