有没有办法使用VBA中的Items.find()从Outlook中提取某些文本?
我需要从批量提取特定的文本(通过9000电子邮件)
我想知道会有这样的工作
Dim Folder as Outlook.MAPIFolder Dim sFolders As Outlook.MAPIFolder Dim iRow As Integer, oRow As Integer Dim MailBoxName As String, Pst_Folder_Name As String, Destination As String ThisWorkbook.sheets(1).Cells(1,1) = "Destinations" For iRow = 1 To Folder.Items.Count ThisWorkbook.Sheets(1).Cells(oRow, 1) = Folder.Items.Find(Destination)
我在几年前只有一些VBA的经验,我需要为我的工作创build这样的系统,这样我就可以从电子邮件正文中提取所需的信息,而不是单独扫描数以千计的电子邮件。
有谁知道一些很好的源代码/教程,我可以看看? 因为每个人都把我带回到同一个地方
谢谢
这是你正在尝试( 从Outlook内testing )? 请修改它从MS-Excel运行。
Sub Sample() Dim myFilter As String, SearchString As String Dim OutlookTable As Table Dim OutlookRow As Row '~~> This is your search string. Change as applicable SearchString = "Siddharth" '~~> Create Query myFilter = "@SQL=" & _ Chr(34) & _ "urn:schemas:httpmail:textdescription" & _ Chr(34) & _ " ci_phrasematch '" & _ SearchString & _ "'" Set OutlookTable = Application.ActiveExplorer.CurrentFolder.GetTable(myFilter) Do Until OutlookTable.EndOfTable Set OutlookRow = OutlookTable.GetNextRow '~~> Print Subject (For example) of that email '~~> which has the search string Debug.Print OutlookRow("Subject") Loop End Sub
有谁知道一些很好的源代码/教程,我可以看看?
教程 :请参阅此MSKB文章
Outlook对象模型提供了用于在Outlook中筛选项目的Find / FindNext , Restrict , GetTable
和AdvancedSearch方法。 我build议在你的情况下使用Restrict
法。 如果有less量项目, Find
或FindNext
方法比筛选更快。 如果集合中有大量项目,那么Restrict
方法明显更快,特别是如果希望find大集合中的less数项目。
您可以阅读关于它们并在以下文章中find示例代码:
- 如何:使用Find和FindNext方法从文件夹(C#,VB.NET)检索Outlook邮件项目
- 如何:使用Restrict方法从文件夹中检索Outlook邮件项目
- 在Outlook中以编程方式进行高级search:C#,VB.NET
MSDN中的“过滤项目”部分深入介绍了所有可能的方法。
Application.ActiveExplorer.CurrentFolder.GetTable(myFilter)
不要在单行代码中使用多个点。 它可能会带来另一个问题到您的代码。 我总是build议打破链属性和方法调用,并在不同的代码行中声明它们。 因此,您将能够在debugging器下看到每个属性和方法返回的结果,并轻松地find问题的原因(如果有的话)。