Save and detach outlook attachment to Excel

Crafty64

Board Regular
Joined
Aug 26, 2010
Messages
55
Hi, I'm using the following code to search within my outlook excel attachments and save them to a specified path. However, after I save each excel attachment I then want to delete the attachment within outlook. I am using the following code which saves the files to excel fine but only seems to delete one attachment?


i = 0
For Each Item In SubFolder.Items
For Each Atmt In Item.Attachments
If Right(Atmt.FileName, 3) = "xls" Then
FileName = "R:\Doug\FP Rates\PAA\" & Atmt.FileName
Atmt.SaveAsFile FileName
Atmt.Delete
i = i + 1
End If
Next Atmt
Next Item
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
This modified procedure works excellent on my PC:

Code:
Sub test()


    For Each Item In CreateObject("Outlook.application").GetNamespace("MAPI").GetDefaultFolder(6).Items
        For Each Atmt In Item.Attachments
            If Right(Atmt.Filename, 4) = "xlsx" Then
                Atmt.SaveAsFile "C:\" & Atmt.Filename
                Atmt.Delete
            End If
        Next
    Next


End Sub

It scans the Inbox and here and there I changed some of the coding, but only in a minor way.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top