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

查看:49
本文介绍了我可以遍历文件夹(包括子文件夹)中的所有 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?

推荐答案

类似这样的...

 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天全站免登陆