我可以遍历包含子文件夹的文件夹中的所有Outlook电子邮件吗? [英] Can I iterate through all Outlook emails in a folder including sub-folders?

查看:599
本文介绍了我可以遍历包含子文件夹的文件夹中的所有Outlook电子邮件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹,其中包含许多电子邮件和子文件夹.在这些子文件夹中,还有更多电子邮件.

I have a folder which contains a number of emails and sub-folders. Within those sub-folders are more emails.

我想写一些VBA,它将遍历某个文件夹中的所有电子邮件,包括任何子文件夹中的电子邮件.这个想法是从每封电子邮件中提取SenderEmailAddressSenderName并对其进行处理.

I'd like to write some VBA which will iterate through all emails in a certain folder, including those in any of the sub-folders. The idea is to extract the SenderEmailAddress and SenderName from every email and do something with it.

我尝试仅使用这两个字段将文件夹导出为CSV,尽管这可行,但它不支持导出子文件夹中保存的电子邮件.因此,需要编写一些VBA.

I've tried just exporting the folder as CSV with only these two fields and whilst this works, it doesn't support exporting emails held in sub-folders. Hence the need to write some VBA.

在我重新发明轮子之前,是否有人有任何代码段或指向站点的链接,这些站点给出了文件夹名称,显示了如何为该文件夹中的每封电子邮件获取MailItem对象,并且后续子文件夹?

Before I go re-inventing the wheel, does anyone have any code snippets or links to sites which, given a folder name, shows how to get a MailItem object for every email in that folder and subsequent sub-folders?

推荐答案

类似这样的事情...

Something like this ...

 Private Sub processFolder(ByVal oParent As Outlook.MAPIFolder)

        Dim oFolder As Outlook.MAPIFolder
        Dim oMail As Outlook.MailItem

        For Each oMail In oParent.Items

        'Get your data here ...

        Next

        If (oParent.Folders.Count > 0) Then
            For Each oFolder In oParent.Folders
                processFolder oFolder
            Next
        End If
End Sub

这篇关于我可以遍历包含子文件夹的文件夹中的所有Outlook电子邮件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆