我有这个脚本来自动保存文件夹中Outlook的附件,但它一次只保存2封电子邮件中的附件。如何将此值增加到3或4?
Const olFolderInbox = 6
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objMailbox = objNamespace.Folders("Mailbox - ABC")
Set objFolder = objMailbox.Folders("Inbox")
Set colItems = objFolder.Items
Set colFilteredItems = colItems.Restrict("[UnRead] = True")
For Each objMessage in colFilteredItems
intCount = objMessage.Attachments.Count
If intCount > 0 Then
For i = 1 To intCount
objMessage.Attachments.Item(i).SaveAsFile "C:\" & _
objMessage.Attachments.Item(i).FileName
Next
End If
objMessage.Unread = False
Next
答案 0 :(得分:0)
试试这个,适用于主收件箱中的电子邮件:
Set outlook = createobject("outlook.application")
Set session = outlook.getnamespace("mapi")
session.logon
Set inbox = session.getdefaultfolder(6) // inbox is 6
For Each m In inbox.items
If m.unread Then
intCount = m.Attachments.Count
If intCount > 0 Then
For i = 1 To intCount
m.Attachments.Item(i).SaveAsFile "C:\pic\" & _
m.Attachments.Item(i).FileName
Next
End If
m.Unread = False
End If
Next
session.logoff
Set outlook = Nothing
Set CaseTitle = Nothing
Set session = Nothing
WScript.Quit
如果您想获取收件箱内文件夹的附件,只需输入以下行:
Set inbox = session.getdefaultfolder(6).Folders("FolderName")