【发布时间】:2020-06-25 07:28:13
【问题描述】:
背景
我在 Outlook 中扫描收件箱,然后根据电子邮件的标题将结果报告给 Excel 电子表格。我将使用与 Microsoft office 关键字中相同的示例,并会说“Office”。
IE:办公室:笔记本电脑有问题。
我需要获取发送邮件的用户名或电子邮件地址,可能还有电子邮件正文中的一些关键字。
我找到了仅通过使用表和行来遍历具有此关键字的项目的方法。
问题
我无法找到将 row.item 从表格转换为电子邮件的方法,也无法获得“sender”或“emailbody”属性。
代码
您需要添加 Outlook 参考
Option Base 1
Sub Outlook_ScanForEmails()
Const TxtTag As String = "http://schemas.microsoft.com/mapi/proptag/"
Const TxtWordSubject As String = "Office:"
Dim OutTable As Outlook.Table
Dim OutRow As Outlook.Row
Dim OutEmail As Outlook.MailItem
Dim OutApp As Outlook.Application: Set OutApp = New Outlook.Application
Dim CounterEmails As Long
Dim TotalEmails As Long
Dim TxtFilter As String: TxtFilter = "@SQL=" & Chr(34) & TxtTag & "0x0037001E" & Chr(34) & " ci_phrasematch '" & TxtWordSubject & "'"
Dim TxtCourse As String
Dim DteReport As Date
Set OutTable = OutApp.Session.GetDefaultFolder(olFolderInbox).GetTable(TxtFilter)
TotalEmails = OutTable.GetRowCount
For CounterEmails = 1 To TotalEmails
Set OutRow = OutTable.GetNextRow
DteReport = OutRow("LastModificationTime")
TxtCourse = OutRow("Subject")
TxtCourse = Right(TxtCourse, Len(TxtCourse) - Len(TxtWordSubject))
Next CounterEmails
End Sub
进一步的想法
我宁愿不遍历每封电子邮件,因为该表将流程缩小到仅迭代我需要的行项目。
【问题讨论】:
-
If you require a writeable object from the Table row, obtain the Entry ID for that row from the default EntryID column in the Table and then use the GetItemFromID method of the NameSpace object to obtain a full item, such as a MailItem or ContactItem, that supports read-write operations.来自msdn.microsoft.com/en-us/vba/outlook-vba/articles/… -
谢谢@Sorceri!但是,我找不到采用这种方法的方法。我试过这个
IDNumber = OutRow.Parent.Columns.Item(1)和Set OutEmail = OutApp.Session.GetItemFromID(OutRow("Subject"))