|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
qisile 发表于 2015-2-12 22:29
请问如何进行将Inbox以及子文件夹里的 收件日期在指定日期(从A日期到B日期)邮件中的附件全部下载另存, ...
已经寻找到部分解决方案,如果能重命名在文件名(不含扩展名)的后面就好了。
对全部的邮件另存附件还在寻找解决方案中- Sub 选择执行()
- Dim i
- i = InputBox("请输入1或2,1代表将For Download中的附件全部保存,2代表将选中的邮件中的附件全部保存", "提示")
- If i = 1 Then
- Call Savetheattachment1
- ElseIf i = 2 Then
- Call Savetheattachment2
- Else
- MsgBox "输入有误!"
- Exit Sub
- End If
- End Sub
- '将For Download中的附件全部保存
- Sub Savetheattachment1()
- Dim olApp As New Outlook.Application
- Dim nmsName As Outlook.NameSpace
- Dim vItem As Object
- Set nmsName = olApp.GetNamespace("MAPI")
- Set myFolder = nmsName.GetDefaultFolder(olFolderInbox)
- Set fldFolder = myFolder.Folders("For Download")
- dd = "C:\Email Attachment Temp"
- If Dir(dd, vbDirectory) = "" Then MkDir dd
- '若无C:\Email Attachment Temp 文件夹则新建该文件夹
- For Each vItem In fldFolder.Items
- '对fldFolder里的每一封邮件进行循环
- For Each att In vItem.Attachments
- '对每一封带附件的邮件
- fn = "C:\Email Attachment Temp" & att.FileName
- 'fn为路径+附件名
- n = 1
- Do Until Dir(fn) = ""
- '如果为空,说明该路径下没有该文件
- fn = "C:\Email Attachment Temp\ " & n & "_" & att.FileName
- '有该文件名则重命名前面加数字
- n = n + 1
- Loop
- att.SaveAsFile fn
- '附件存到C:\Email Attachment Temp中
- Next
- Next
- Set fldFolder = Nothing
- Set nmsName = Nothing
- MsgBox "已导出全部附件到“C:\Email Attachment Temp”,请查看。"
- End Sub
- '将选中的邮件中的附件全部保存
- Sub Savetheattachment2()
- dd = "C:\Email Attachment Temp"
- If Dir(dd, vbDirectory) = "" Then MkDir dd
- '若无C:\Email Attachment Temp 文件夹则新建该文件夹
-
- Dim objItem As Outlook.MailItem
- For Each objItem In Application.ActiveExplorer.Selection
- If objItem.Class = olMail Then
- For Each att In objItem.Attachments
- '对每一封带附件的邮件
- fn = "C:\Email Attachment Temp" & att.FileName
- 'fn为路径+附件名
- n = 1
- Do Until Dir(fn) = ""
- '如果为空,说明该路径下没有该文件
- fn = "C:\Email Attachment Temp\ " & n & "_" & att.FileName
- '有该文件名则重命名前面加数字
- n = n + 1
- Loop
- att.SaveAsFile fn
- '附件存到C:\Email Attachment Temp中
- Next
- End If
- Next
-
- MsgBox "已导出全部附件到“C:\Email Attachment Temp”,请查看。"
- End Sub
复制代码 |
|