尝试从Outlook中提取信息并输入到Excel

人气:992 发布:2022-09-22 标签: outlookdev

问题描述

您好我是一名创作项目的学生,还在学习VBA的绳索。

Hi I'm a student working on a creative project and still learning the ropes of VBA.

我正在尝试编写代码进入Outlook,找到一个文件夹,在该文件夹中查找特定的电子邮件,复制某些信息,然后将其粘贴到Excel中的Excel文档或新电子邮件中(这将是理想的)。这就是我用开始的,但不确定如何离开这里。

I am trying to write code to enter Outlook, find a folder, find a specific email in that folder, copy certain information, and then paste it either into an excel document or a new email in outlook (this would be ideal). This is what I have started out with, but unsure how to go from here.

任何帮助都会非常感激!

Any help would be much much much appreciated!

推荐答案

您好,

看起来您找到了该文件夹(收件箱的子文件夹)。现在,您需要找到符合您条件的所需电子邮件。要实现这一目标,您需要使用 查找 / FindNext 或 限制Items类的方法。您可以在以下文章中阅读有关它们的更多信息:

Looks like you have found the folder (a subfolder of the Inbox). Now you need to find the required email(s) that correspond to your conditions. To get that working you need to use the Find/FindNext or Restrict methods of the Items class. You can read more about them in the following articles:

如何:使用Find和FindNext方法从文件夹(C#,VB.NET)中检索Outlook邮件项目

如何:使用Restrict方法从文件夹中检索Outlook邮件项目

Sub MoveItems()  
    Dim myNamespace As Outlook.NameSpace  
    Dim myFolder As Outlook.Folder  
    Dim myItems As Outlook.Items  
    Dim myRestrictItems As Outlook.Items  
    Dim myItem As Outlook.MailItem  

    Set myNamespace = Application.GetNamespace("MAPI")  
    Set myFolder = _  
        myNamespace.GetDefaultFolder(olFolderInbox)  
    Set myItems = myFolder.Items  
    Set myRestrictItems = myItems.Restrict("[Categories] = 'Business'")  
    For i =  myRestrictItems.Count To 1 Step -1  
        myRestrictItems(i).Move myFolder.Folders("Business")  
    Next  
End Sub

此外,如果您需要搜索多个文件夹中的项目,您可能会发现 AdvancedSearch Application类的方法。在Outlook中使用 AdvancedSearch 方法的主要好处是:

Also if you need to search for items in multiple folders you may find the AdvancedSearch method of the Application class. The key benefits of using the AdvancedSearch method in Outlook are:

搜索在另一个线程中执行。您不需要手动运行另一个线程,因为 AdvancedSearch 方法会在后台自动运行它。 可以在任何位置搜索任何项目类型:邮件,约会,日历,笔记等,即超出某个文件夹的范围。 限制和 Find / FindNext 方法可以应用于特定的 < em style ="zoom:1"> Items 集合(请参阅Outlook中Folder类的Items属性)。 完全支持 DASL 查询(自定义属性也可用于搜索)。您可以在中了解更多相关信息 过滤文章。要提高搜索效果, 如果启用了即时搜索,则可以使用即时搜索关键字商店(请参阅 商店类的 IsInstantSearchEnabled 属性。 您可以随时使用Search类的Stop方法停止搜索过程。 The search is performed in another thread. You don’t need to run another thread manually since the AdvancedSearch method runs it automatically in the background.Possibility to search for any item types: mail, appointment, calendar, notes etc. in any location, i.e. beyond the scope of a certain folder. The Restrict and Find/FindNext methods can be applied to a particular Items collection (see the Items property of the Folder class in Outlook).Full support for DASL queries (custom properties can be used for searching too). You can read more about this in the Filtering article in MSDN. To improve the search performance, Instant Search keywords can be used if Instant Search is enabled for the store (see the IsInstantSearchEnabled property of the Store class).You can stop the search process at any moment using the Stop method of the Search class.

了解更多关于以编程方式在Outlook中进行高级搜索:C#,VB.NET文章。

最后,要创建一个新的Outlook项目,你可以使用 Items.Add 或 Application.CreateItem 方法。请查看以下文章以获取示例代码和进一步说明:

And, finally, to create a new Outlook item you can use the Items.Add or Application.CreateItem methods. Take a look at the following articles for the sample code and further explanations:

如何以编程方式创建和显示新的Outlook邮件项目:C#,VB.NET

如何:以编程方式创建和发送Outlook邮件

370