|
本帖最后由 whatyang 于 2015-3-10 21:00 编辑
在论坛上我找到如下代码,是用于下载收件夹下的所有邮件的附件,现在先下载指定文件夹(如文件夹名为“历史邮件备案”),应该如何修改代码
另,如果附件有重名时,自动重命名怎么写?
再另,求系统自动其他文件夹的改法,如下载 发件夹下所有邮件的附件,又怎么写呢?...
还另,如下载指定文件类型的附件,又该怎么写(如 *.rar *.zip *.xls *.xlsx)
谢谢!
Sub Savetheattachment()
Dim olApp As New Outlook.Application
Dim nmsName As Outlook.NameSpace
Dim fldFolder As Outlook.Folder
Dim vItem As Object
Set nmsName = olApp.GetNamespace("MAPI")
Set fldFolder = nmsName.GetDefaultFolder(olFolderInbox)
If fldFolder.UnReadItemCount > 0 Then
For Each vItem In fldFolder.Items
If vItem.UnRead = True Then
'-----保存附件-------
For Each att In vItem.Attachments
att.SaveAsFile "D:\新建文件夹\" & att.FileName
Next
'------保存附件--------
vItem.UnRead = False
End If
Next
End If
Set fldFolder = Nothing
Set nmsName = Nothing
MsgBox "OK"
End Sub
|
|