该代码从 Excel 中的“A”列中读取行,在 Outlook 中查找它们并将附件下载到范围(“E3”)中的文件夹,该文件夹会根据计算机而变化。
但是,在我的电脑上它运行良好,在我同事的电脑上它不下载文件。
Sub Descarga()
Dim it, at As Variant, t As Long
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim olItem As Object
Dim mailitem As Outlook.mailitem
Dim olAtt As Outlook.Attachment
Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.GetDefaultFolder(olFolderInbox)
For Each it In CreateObject("outlook.application").GetNamespace("MAPI").GetDefaultFolder(6).Items
For t = 1 To Range("A" & Rows.Count).End(xlUp).Row
If InStr(it.Subject, Cells(t, 1)) Then
For Each at In it.Attachments
at.SaveAsFile (Range("E3")) & "\" & at.DisplayName 'Range("E3") is the path
Next
End If
Next
Next
End Sub