我试图保存多个子文件夹中的附件。我的代码没有遍历子文件夹,它只保存一个附件。
有人可以帮帮我吗?这是我的代码:
Private WithEvents Items As Outlook.Items
Private Count As Integer
Private Sub Application_Startup()
Dim objApp As Outlook.Application
Dim objNameSpace As Outlook.NameSpace
Dim path_location As String
' Get the items in the Inbox folder
Set objApp = Outlook.Application
Set objNameSpace = objApp.GetNamespace("MAPI")
Set Items = objNameSpace.Folders("Archives_May_2016").Folders("Inbox").Folders("subfolder1").Items
path_location = "C: \emails" & "\Attachments\"
For Each Item In Items
Items.Item(1).Attachments.Count
' Initialize count
strFile = Items.Item(1).Attachments.Item(1).FileName
strFile = path_location & strFile
Items.Item(1).Attachments.Item(1).SaveAsFile strFile
Count = Count + 1
Next
End Sub
答案 0 :(得分:0)
由于您在Items
之前设置for loop
,因此您始终访问同一个文件,但在其中您正在执行此操作:
Items.Item(1).Attachments.Count
尝试将for循环更改为:
For Each Item In Items
atts = Item.Attachments.Count
For i = 1 to atts
strFile = Item.Attachments.Item(i).FileName
strFile = path_location & strFile
Item.Attachments.Item(i).SaveAsFile strFile
Next
Next