可以通过以下步骤实现:
Sub ImportEmailsFromOutlook()
Dim OutlookApp As Object
Dim OutlookNamespace As Object
Dim Folder As Object
Dim OutlookMail As Object
Dim i As Integer
' 创建Outlook应用程序对象
Set OutlookApp = CreateObject("Outlook.Application")
' 获取Outlook命名空间
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
' 指定要导入的Outlook文件夹路径,例如"Inbox\Subfolder"
Set Folder = OutlookNamespace.GetDefaultFolder(6).Folders("Subfolder")
' 在Excel中创建表头
Range("A1").Value = "发件人"
Range("B1").Value = "主题"
Range("C1").Value = "时间"
' 遍历文件夹中的每封电子邮件
i = 2
For Each OutlookMail In Folder.Items
' 将发件人、主题和时间导入Excel
Cells(i, 1).Value = OutlookMail.SenderName
Cells(i, 2).Value = OutlookMail.Subject
Cells(i, 3).Value = OutlookMail.ReceivedTime
i = i + 1
Next OutlookMail
' 释放对象
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub
这样,您就可以使用VBA将Outlook子文件夹电子邮件导入Excel了。
领取专属 10元无门槛券
手把手带您无忧上云