Office中国论坛/Access中国论坛
标题:
[原创] 小闻趣话之一获得邮件的中全部附件
[打印本页]
作者:
闻启学
时间:
2019-4-14 11:01
标题:
[原创] 小闻趣话之一获得邮件的中全部附件
在某个单位办公室
上午9:50分,江少忽然被上司奉召到办公室;少刻,江少苦着面,捧住笔记本电脑从里面出来。急忙到座位边敲击键盘起来。
旁边斌哥打趣说到“江少,怎么啦。进去后变了天”,江少无奈讲“老佛爷让我将邮箱里邮件的附件全部保存下来!。在上午之前完成”,“老佛爷,是不是有点令人难做,不怕,找人帮你!”,“小闻,你过来” 小闻慢慢地过来了,"怎么啦"。“无,我们三个人分开任务,将邮箱里邮件的附件全部下载”
“斌哥,开玩笑,谁有本事将邮箱分三人共享”。小闻猫一眼笔记本电脑,自言自语地讲“幸好他用Outlook,还是完整版本,否则我无办法了”,回头对江少讲“帮你搞好,中午饭你请客”江少,斌哥讲 “肯定?”,小闻笑而不答。
Sub GetAttachmentName()
'//获得邮件中的附件
Dim OutApp As outlook.Application
Dim myNamespace As NameSpace
Dim myFolder As MAPIFolder
Dim Folder As MAPIFolder
Dim iMail As outlook.MailItem
Dim attFilename As String
Dim myAttachment As outlook.Attachment
Dim mytmp As String
Dim tmpa As String
On Error Resume Next
Dim ExcelApp
Set OutApp = New outlook.Application
Set myNamespace = OutApp.GetNamespace("MAPI")
'Set myFolder = MyNameSpace.PickFolder
Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox) '//获得收件箱文件夹
For i = 1 To myFolder.Folders.Count
Set Folder = myFolder.Folders(i)
For Each iMail In Folder.Items
For Each myAttachment In iMail.Attachments '//获得邮件的附件
attFilename = myAttachment.FileName
If attFilename Like "*.xls?" Then '//判断附件的类型
tmpa = Split(attFilename, ".")(1)
myAttachment.SaveAsFile "D:\邮件的附件" & attFilename '//保存附件
End If
Next
Next iMail
Next
Set iMail = Nothing
Set myFolder = Nothing
Set myNamespace = Nothing
Set Application = Nothing
End Sub
复制代码
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3