Outlook Macro

mk000

Board Regular
Joined
Dec 10, 2004
Messages
234
Hi all,

In Outlook v11 there is an issue I have seen many posts around the internet on. If you print an email with an attachement, it does not list the attachments on the print. It does this in Outlook Express. I do not believe there to be an option to make this available so I've been looking for a macro to do the magic.

This macro ideally would, on print, insert the name of all attachments to the email below the normal headings... see below...

NAME______________
From: yadaa yaddy
Sent: yadaa yaddy
To: yadaa yaddy
Subject: yadaa yaddy
Attachment: FILE.name <<<

BODY


I looked around, and I found the following code, but it does nothing for me. Please advise.

Thanks
MK

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
' instantiate objects declared WithEvents
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub

Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
Call AppendNames(Item)
End Sub

Private Sub AppendNames(ByVal objItem As Object)

Dim objAttach As Attachment
Dim strBody As String
Dim strAttach As String
Dim strCRLF As String
Dim intFormat As Integer

strAttach = ""

'Don't process if it's not an e-mail
If objItem.MessageClass <> "IPM.Note" Then Exit Sub
'Don't process if there aren't attachments
If objItem.Attachments.Count = 0 Then Exit Sub

If objItem.HTMLBody <> vbNullString Then
strCRLF = "
"
Else
strCRLF = vbCrLf
End If

'Build the names into a string
strAttach = strCRLF & strCRLF
For Each objAttach In objItem.Attachments
strAttach = strAttach & "Attached File: " & objAttach.DisplayName & strCRLF
Next

'Insert the names into the body
If objItem.HTMLBody <> vbNullString Then
strBody = objItem.HTMLBody
strBody = Replace(strBody, "</BODY>", strAttach & "</BODY>")
objItem.HTMLBody = strBody
Else
strBody = objItem.Body
strBody = strBody & strAttach
objItem.Body = strBody
End If

objItem.Save

End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I have Outlook 2003 (11.6359.6408) SP1. My attachments are listed with the code you provided, or without it. What version are you running?
 
Upvote 0

Forum statistics

Threads
1,224,847
Messages
6,181,325
Members
453,032
Latest member
Pauh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top