PDA

View Full Version : Solved: Printing Sent Email



chrismc
06-27-2006, 10:51 AM
Hi,

I have a colleague who wants to print a hard copy each time she sends an email to a particular recipient.

Is it possible to incorporate a little bit of VBA with Outlook rules to do the job. If so, please tell me how? Otherwise, how would you suggest I set this up?

Thanks in advance.

Zack Barresse
06-27-2006, 11:13 AM
Hi there,

Check out this thread: http://www.vbaexpress.com/forum/showthread.php?t=1867&highlight=print+email

chrismc
06-29-2006, 12:52 PM
Based upon the start you gave me here is what I came up with:

Objective
All emails sent to a particular recipient need to be printed at the time they are sent.

Logic
Using the standard rules function any outgoing emails can be checked and if addressed to a particular person a copy of the email can saved in a separate folder. Using the Outlook programming language (VBA - Visual Basic for Applications) it is possible for Outlook to continually monitor the specific folder and, whenever an email is saved to it, the user can be asked if they want it to be printed. After printing the copy email is deleted. If the user does not want to print it the copy email is deleted.

Limitations
Outlook will print to whichever printer was the default printer when Outlook was started. If the default printer is changed whilst Outlook is running then Outlook must be closed and restarted to pick up the correct printer. It is not possible using this programming to choose a printer at the time of sending the email.

Only tested with Outlook 2003.

Setting up:
Rule
Inbox
Tools
Rules and Alerts
New Rule
Start from blank rule
Check messages after sending
Next
Sent to people or distribution list (then specify details by clicking on link)
Next
Move a copy to specified folder (then specify details by clicking on link)
Next
Next
Specify a name at the top of the dialog if desired
Finish

Folder
Inbox
Right click on "Mailbox - your name"
New folder
Make the name Temp
OK

Inserting VBA Code
Inbox
ALT-F11 (to open the editor)
Copy the code into the right hand window (you may need to left click on ThisOutlookSession to open the window)
Close Outlook and restart it.

VBA code
Dim WithEvents TargetFolderItems As Items
Private Sub Application_Startup()
Dim ns As Outlook.NameSpace
Set ns = Application.GetNamespace("MAPI")
Set TargetFolderItems = ns.Folders.item("Mailbox - XXXXXXXXXXXXXX").Folders.item("Temp").Items
Set ns = Nothing
End Sub
Private Sub TargetFolderItems_ItemAdd(ByVal item As Object)
Dim AskUser as boolean
Askuser = MsgBox("Do you want Outlook to print the email you just sent?" & vbCr _
& vbcr & "Email Subject: " & item.Subject, vbYesNo)
If Askuser = vbYes Then
item.PrintOut
End If
item.Delete
End Sub


Thanks.