从Excel中将Outlook 2007邮件信息提取到Excel - 文件夹/主题

时间:2013-08-21 13:33:38

标签: excel-vba outlook text-extraction vba excel

我想将具有特定主题部分的邮件主题提取到Excel工作表(来自Excel)。到目前为止,我只能提取正文,而不是主题,代码搜索主题的部分找不到任何内容。您能否就如何查找我的电子邮件(不同的getdefault文件夹?)提出任何建议并提取主题?

提前致谢

Sub Work_with_Outlook()

Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.Namespace
Dim Fldr As Outlook.MAPIFolder
Dim olMail As Variant
Dim sir() As String

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox).Folders("Test")
Set myTasks = Fldr.Items

Set olMail = myTasks.Find("[Subject] = ""*Test*"")
If Not (olMail Is Nothing) Then
sir = Split(olMail.Body, vbCrLf)
For i = 1 To UBound(sir)
ActiveWorkbook.Sheets("Sheet1").Cells(i, 1).Value = sir(i)
Next i

End If

End Sub

1 个答案:

答案 0 :(得分:0)

你有没有尝试过改变..

sir = Split(olMail.Body, vbCrLf)

sir = Split(olMail.Subject, vbCrLf)