Solved

how to extract files from outlook 2013 with vba on access

Posted on 2014-12-08
3
276 Views
Last Modified: 2014-12-17
hi


i have this code to loop on microsoft access 2013 form that loop all emails on outlook. what i have to add to the  code to check every email if it's have any attachment file and if so to extract it.

this is the code
Dim oApp As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oInbox As Outlook.MAPIFolder
Dim oMailItem As Outlook.MailItem

Set oApp = New Outlook.Application
Set oNS = oApp.GetNamespace("MAPI")
Set oInbox = oNS.GetDefaultFolder(olFolderInbox)

For Each oMailItem In oInbox.Items
    MsgBox oMailItem.Attachments
Next

Open in new window

0
Comment
Question by:bill201
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40486455
You would do a look on oMailItem.Attachments() and, use .SaveAsFile(strDirectoryAndFileName)
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 500 total points
ID: 40487204
Given that Outlook only wants one instance open, fire it up with the following code.
The rest should get you very close to what you need

Option Explicit
Option Compare Database

Public Function FireOutlook() As Outlook.Application
On Error Resume Next
Dim objOutlook As Outlook.Application

Set objOutlook = GetObject(, "Outlook.Application")
'MsgBox Err.Number & " " & Err.Description
If Err.Number = 429 Then
    Err.Clear
    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")
End If

Set FireOutlook = objOutlook

End Function


Sub GetAttachments()
Dim OutlookApp As Outlook.Application
Dim oNameSpace    As Namespace
Dim oFldrList     As Outlook.MAPIFolder

Dim ThePath As String
Dim ns As Namespace
Dim Item As Object
Dim olItem As MailItem
Dim olAtt As Outlook.Attachment
Set OutlookApp = FireOutlook
Dim i As Integer
i = 0
ThePath = "c:\temp\" 'change this to suit you
Set oNameSpace = OutlookApp.GetNamespace("MAPI")
Set oFldrList = oNameSpace.GetDefaultFolder(olFolderInbox)

For Each olItem In oFldrList.Items
    For Each olAtt In olItem.Attachments
       olAtt.SaveAsFile ThePath& olAtt.FileName
       i = i + 1
    Next
Next

If i > 0 Then
   MsgBox "I found " & i & " attached files." _
      & vbCrLf & "I have saved them on the" & ThePath & " Path." _
      & vbCrLf & vbCrLf & " ", vbInformation, "Download Finished!"
Else
   MsgBox "I didn't find any attached files in your mail.", vbInformation, _
   "Finished!"
End If

End Sub

Open in new window

0
 

Author Closing Comment

by:bill201
ID: 40505904
thanks alot
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question