Angel Carvajal
New Member
- Joined
- Feb 22, 2022
- Messages
- 4
- Office Version
- 365
- 2021
- 2019
- 2016
- 2013
- Platform
- Windows
I have a code that downloads attachments according to the subject, this subject is extracted line by line from excel to outlook. On my pc it works perfectly, but when checking it on another computer it doesn't throw an error message, but it doesn't download the files either.
sub download()
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 olItem In olFolder.Items
If olItem.Class = olMail Then
Set mailitem = olItem
For i = 1 To X
If InStr(1, mailitem.Subject, Cells(i, 1)) Then
Debug.Print mailitem.Subject
For Each olAtt In mailitem.Attachments
olAtt.SaveAsFile (ThisWorkbook.Sheets(1).Cells(3, 5) & "\" & olAtt.Filename)
Next olAtt
End If
Next
End If
Next olItem
End Sub
Thanx!!
sub download()
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 olItem In olFolder.Items
If olItem.Class = olMail Then
Set mailitem = olItem
For i = 1 To X
If InStr(1, mailitem.Subject, Cells(i, 1)) Then
Debug.Print mailitem.Subject
For Each olAtt In mailitem.Attachments
olAtt.SaveAsFile (ThisWorkbook.Sheets(1).Cells(3, 5) & "\" & olAtt.Filename)
Next olAtt
End If
Next
End If
Next olItem
End Sub
Thanx!!