Hi,
I need to download lots of attachments from various folders in outlook and trying to use the code below. The issue is that on some folders it works just fine but for others i get a runtime error 13 on the line in red. Any ideas on why that's happening?
Also, is it possible to ammend the code so that it downloads the attachments from the main folder, sub folders and sub sub folders?
credit - https://www.youtube.com/watch?v=NMAkhIcTW3A
I need to download lots of attachments from various folders in outlook and trying to use the code below. The issue is that on some folders it works just fine but for others i get a runtime error 13 on the line in red. Any ideas on why that's happening?
Also, is it possible to ammend the code so that it downloads the attachments from the main folder, sub folders and sub sub folders?
Sub download_attachments()
Dim olapp As Outlook.Application
Dim olmail As MailItem
Dim Att As Object
Dim olfolder As Outlook.Folder
Dim namap As NameSpace
strfolderpath = "U:\test_folder"
Set olapp = CreateObject("Outlook.application")
Set olmail = olapp.CreateItem(olMailItem)
Set olfolder = olapp.GetNamespace("MAPI").PickFolder
For Each olmail In olfolder.Items
If TypeName(olmail) = "MailItem" Then
y = 1
For Each Att In olmail.Attachments
strfile = olmail.Attachments.Item.FileName
strfile = strfolderpath & strfile
olmail.Attachments.Item.SaveAsFile strfile
y = y + 1
Next Att
Else
Exit Sub
End If
Next
End Sub
credit - https://www.youtube.com/watch?v=NMAkhIcTW3A