【发布时间】:2021-09-09 11:02:11
【问题描述】:
在 Excel 中,我正在查找一个人的电子邮件地址,然后我想找到最后一封电子邮件(发送或接收)并触发对此电子邮件的回复。此回复由 Excel 中的按钮触发。
Dim a As Integer
Dim objOutlook As Object
Dim objMail As Object
Dim rngBody As Range
Dim rngAttach As Range
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
EmailStr = "sombody@gmail.com" (dummy replacement for my find the email adress in excel spreadsheet
然后我需要在 Outlook 中查找发往/发自该地址的电子邮件,然后回复最新的。
我所做的是向此人发送一封新电子邮件,但不知道如何查找和回复
With objMail
.To = EmailStr
.CC = AMEmail
.Subject = TitleMail
.HTMLBody = BodyStr & Signature
.ReadReceiptRequested = True
.Display 'Instead of .Display, you can use .Send to send the email _
or .Save to save a copy in the drafts folder
Set objOutlook = Nothing
Set objMail = Nothing
Set rngBody = Nothing
Set rngAttach = Nothing
更新:仍在挣扎,但目前没有更多崩溃。我现在卡在这里的地方:
Private Sub CommandButton2_Click()
Dim olApp As Object
Dim olNs As Object
Dim olFldr As Object
Dim olItems As Object
Dim olItemReply As Object
Dim i As Long
Dim emailStr As String
Dim filter As String
Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
Set olFldr = olNs.GetDefaultFolder(6) ' olFolderInbox
Debug.Print "olFldr: " & olFldr
emailStr = "sombody@gmail.com" '(email address in Excel spreadsheet)
Debug.Print "emailStr: " & emailStr
Set olItems = olFldr.Items
Debug.Print olItems.Count
'finds all 19 items in my inbox with msgbox(olItems.count)
filter = "[SenderEmailAddress] = '" & emailStr & "'"
Debug.Print filter
Set olItems = olFldr.Items.Restrict(filter)
Debug.Print olItems.Count
'finds 0 items now ??? why....
End sub
【问题讨论】:
-
您有 Excel 中的所有电子邮件吗?或者您是否必须使用其他应用程序(例如 Outlook 或 GMail)来查找以前的电子邮件?
-
我想从 excel 中获取电子邮件地址,并在 Outlook 中找到该人的最后一封电子邮件。应该澄清问题
-
你应该用更多的细节来更新你的问题。并包括您正在使用的方法/工具。你在 Excel 中使用 VBA 吗?你可以为你的 Outlook 编写 VBA (Alt-F11) 吗?
-
对于收到的邮件,一种可能是
.RestrictonSenderEmailAddress。 stackoverflow.com/a/42547062/1571407。对于后期绑定,您必须将所有 Outlook 声明为Object并将 olFolderInbox 更改为 6 并将 olMail 更改为 43。