File attachment

  • Thread starter Thread starter Tom Antrim
  • Start date Start date
T

Tom Antrim

How can I retrieve a file attached to an email and put it
in a specific folder. I want to be able to use a macro
that I have written that works fine if the excel file is
already in the folder. The trick is to get it from being
attached to the email to the folder.
 
If you are using outlook as mail system the following code could be usefull
(tested with Excel):

'---------------------------------------------------
' Include 'Microsoft Outlook 11.0 Object Library'
' using Extras --> AddIns into this project
'---------------------------------------------------
Sub TestIt()
On Error Resume Next
Dim ns As Namespace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer

Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
i = 0
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
FileName = "C:\_work\Atmt\" & i & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
Next Atmt
Next Item
End Sub
 
Back
Top