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
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,958
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,599
Messages
5,597,105
Members
414,125
Latest member
iQQ

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
Top