|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
当遍历整个收件箱的时候,遇到会议就报错,能否跳过会议,或是修改哪里能将会议也抓出来
代码:
- Sub GetSanderAdressAndBody() '//获得收件箱的子文件夹的邮件
- Dim Application As outlook.Application
- Dim myNamespace As NameSpace
- Dim myFolder As MAPIFolder
- Dim Folder As MAPIFolder
- Dim iMail As outlook.MailItem
- Dim ExcelApp
- Set ExcelApp = GetObject("", "Excel.Application")
- Set wbk = ExcelApp.Workbooks.Open("f:/测试中.xlsx")
- Set wst = wbk.Sheets(1)
- Set Application = New outlook.Application
- Set myNamespace = Application.GetNamespace("MAPI")
- 'Set myFolder = MyNameSpace.PickFolder
- Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox) '//获得收件箱文件夹
- '// myNamespace.Folders.Count
- For i = 1 To myFolder.Folders.Count
- Set Folder = myFolder.Folders(i)
- For Each iMail In Folder.Items
- j = j + 1
- wst.Cells(j, 5) = iMail.ReceivedTime '//接收邮件日期时间
- wst.Cells(j, 4) = Folder.Name '//所在文件夹名称
- wst.Cells(j, 1) = iMail.To '//发件人
- wst.Cells(j, 2) = iMail.CC '//抄送人
- wst.Cells(j, 3) = iMail.Body '//正文
- Next iMail
- Next
- wbk.Close True
- Set iMail = Nothing
- Set myFolder = Nothing
- Set myNamespace = Nothing
- Set Application = Nothing
- End Sub
|
|