Hi, I'm trying to create a macro in Outlook 2007 to print all of the attachments in an email. I would rather not have to save them to the hard drive and print them from different programs the way I've seen some code examples do it on the web. It seems you should be able to do this all from within Outlook. Here's what I have so far, pieced together from different code examples I've found.
Quote:
Sub GetAttachments()
On Error GoTo GetAttachments_err
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim Filename As String
Dim emlApp As Object
Dim emlDoc As Object
Dim i As Integer
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox).Parent.Folders.Item("Promissory Emails")
i = 0
If Inbox.Items.Count = 0 Then
MsgBox "There are no messages in the inbox.", vbInformation, "Nothing Found"
Exit Sub
End If
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
'The following two lines don't work. This is what I need help with.
Set emlDoc = Atmt
Item.Atmt.Item(i).PrintOut
i = i + 1
Next Atmt
Next Item
If i > 0 Then
MsgBox "I have found " & i & " attached files." & vbCrLf _
& "I have printed them." _
& vbCrLf & vbCrLf & "Have a nice day!", vbInformation, "Finished!"
Else
MsgBox "I didn't find any attachments in your mail.", vbInformation, "Finished!"
End If
GetAttachments_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Exit Sub
GetAttachments_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information:" _
& vbCrLf & "Macro Name: GetAttachments" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume GetAttachments_exit
End Sub
Any help would be appreciated as I don't really know VB at all.