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
 
Wow, It works great. Thanks alot. Its not what you know
but who you know.

Thanks Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top