Outlook Automation - Attachment Download

Status
Not open for further replies.

tdromgoo

Beta member
Messages
5
Can anyone help me modify my code so I can download attachments?

Below is the code that I am currently using.
'**************************************************

Private Sub GetFolderInfo(fldFolder As Mapifolder)
' This procedure prints to the Immediate window information
' about items contained in a folder.
Dim objItem As Object
Dim dteCreateDate As Date
Dim strSubject As String
Dim strItemType As String
Dim strBody As String
Dim intCounter As Integer


On Error Resume Next

Debug.Print "Folder '" & fldFolder.Name & "' (Contains " & fldFolder.Items.Count & " items):"

If LCase(fldFolder.Name) = "inbox" Then
For Each objItem In fldFolder.Items
intCounter = intCounter + 1
With objItem
If LCase(.Subject) = "custom headers fix" Then
dteCreateDate = .CreationTime
strSubject = .Subject
strItemType = TypeName(objItem)

.SaveAsFile "D:\My Documents\Email Reader\test.asp"

Debug.Print vbTab & "Item #" & intCounter & " - " _
& strItemType & " - created on " _
& Format(dteCreateDate, "mmmm dd, yyyy hh:mm am/pm") _
& vbCrLf & vbTab & vbTab & "Subject: '" _
& strSubject & "'" & vbCrLf _
& strBody & vbCrLf
End If
End With
Next objItem
End If
End Sub


Private Sub Form_Load()
Dim MyNS As NameSpace
Set MyNS = Application.GetNamespace("MAPI")
Dim fldFolder As Mapifolder
Set fldFolder = MyNS.GetDefaultFolder(olFolderInbox)
Call GetFolderInfo(fldFolder)
End Sub
 
The attachment is an item on the attachements collection. So try:

for i = 1 to objItem.Attachments.count
objItem.Attachments.item(i).SaveAsFile PathString
next

Jack
 
Status
Not open for further replies.
Back
Top Bottom