|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
如何将outlook的收件箱里的邮件里的文件导出:
导入程序的关键需要引用一个outlook对象
1、导入至excel或access,如下代码为excel里的一个宏:
Sub Exprot_Mail_xl()
Dim myolapp As New Outlook.Application
Set myNameSpace = myolapp.GetNamespace("MAPI")
Set myfolder = myNameSpace.GetDefaultFolder(olFolderInbox)
For i = 1 To myfolder.Items.Count '简单for...next循环,将所有邮件导出,myfolder.Items.Count是收件箱里邮件的数量
Set mymailitem = myfolder.Items(i)
With mymailitem
Sheet1.Cells(i, 1) = .Subject
Sheet1.Cells(i, 2) = .SenderName
Sheet1.Cells(i, 3) = .Body
End With
Next
xlapp.quit
End Sub
**********************************************************************
2、导出成文本文件:
Sub Exprot_Mail_txtfile()
Dim myolapp As New Outlook.Application
Set myNameSpace = myolapp.GetNamespace("MAPI")
Set myfolder = myNameSpace.GetDefaultFolder(olFolderInbox)
For i = 1 To myfolder.Items.Count '简单for...next循环,将所有邮件导出,myfolder.Items.Count是收件箱里邮件的数量
Set mymailitem = myfolder.Items(i)
With mymailitem
.SaveAs "c:\电子邮件\" + .Subject + ".txt", olTXT
End With
Next
xlapp.quit
End Sub
**************************************************** |
|