Printing Custom Outlook Forms and Reports
Microsoft Word and Microsoft Excel are probably the best print engines for custom printing of Outlook forms and folder data. In Word, create a template with form fields and bookmarks, then use VBScript or VBA code to push the Outlook data into the template. You can do the same thing with Excel using range names.
My book -- Microsoft Outlook Programming: Jumpstart for Administrators, Developers, and Power Users -- devotes a full chapter to printing forms and reports with folder views, Microsoft Excel and Microsoft Word. You can download the source code, which includes several sample Excel and Word printing projects, using the the Get Sue's Code link at the bottom of any page.
Reports without code
Method 1: Copy and paste to Excel
- Arrange the columns in a table view to show the fields you're interested in, in the order you want.
- Choose Edit | Select All, then Edit | Copy.
- Switch to an Excel worksheet, then choose Edit | Paste.
Once you have the data in Excel, you can do subtotals, totals, etc. with it and print the worksheet. You can also use this method to export custom fields to Excel.
Method 2: Saved Search
- Choose Tools | Advanced Find, set up your search, and run it. Note that you can search across multiple folders in your Exchange mailbox or a Personal Folders .pst file.
- Arrange the columns in a table view to show the fields you're interested in, in the order you want, with the column widths you need to display the full data in each field.
- Choose File | Print to print the results.
- Choose File | Save Search to save the search as an .oss file.
If you can send the .oss file to other users, they can run the search, then print the results, too.
Many thanks to Scott Perley on the outlook-dev discussion list for this method!
Method 3: Mail merge to Word
This method works only with contacts, but it supports any custom fields visible in the folder. The secret is to start the merge from the Outlook contacts folder with the Tools | Mail Merge command and choose to merge all fields in the folder. From there, just construct your document as you normally would. The folder's custom fields will be visible in the fields list. See: To start a Word letter from a Microsoft Outlook contact
WYSIWYG form printing
XPrint
XPrint is a free ActiveX control and add-in from Microsoft for printing exactly what you see on an Outlook form, buttons and all. It has enough serious limitations (see below) that I don't recommend it. If you choose to use it, everyone in your organization who needs WYSIWYG printing will need to install it, which will place an .ocx control and help file in the Office\Addins folder. It also adds XPrint Addin to the Add-in Manager; this add-in replaces the normal Print dialog for customized Message and Post forms, allowing you to get some WYSIWYG printing for those without adding the control to the form.
The add-in prints all customized pages. The ActiveX control prints only the page on which you place it. If you can't add the XPrint ActiveX control to the control toolbox, try running Regsvr32 to register it:
regsvr32 "c:\program files\microsoft office\office\addins\xprint.ocx"
XPrint cannot print the Body (message body), To, Cc or Bcc fields, though the first article below offers a workaround. See:
Custom Word Templates and Code
For best results, automate Word, pushing data into either a blank document or a document created from a template, filling in form fields or insert text at bookmarks. Using a template lets you divide up the work: Someone else can lay out and format the template. You will find examples for this method in my book and among the samples below.
TIP: If you use the Word form field method, don't use a form field for the body of a message or for any other large field or field containing carriage return/line feeds. Instead use a bookmark, with a syntax like this:
objDoc.Bookmarks("Other").Range.InsertAfter Item.Body
this Range.InsertAfter technique any time you need to insert data that contains carriage returns. Here's another example, inserting the list of attachments from a message (Item) into a Word document (objDoc) at a bookmark named Attachment_List:
strAtts = "" For Each att in Item.Attachments strAtts = strAtts & att.DisplayName & vbCrLf Next objDoc.Bookmarks("Attachment_List").Range.InsertAfter strAtts
Printing an HTML Message or Post
An all-Outlook method is to create a new message or post and set its HTMLBody property to a fully tagged HTML string containing the information you want to print out. The sample at Sending a mail message with today's appointments shows how to construct such a message from a bunch of appointments. Instead of using .Display to display the message, you could use .PrintOut to print it out. Section 22.1.4 in my book describes this method in detail.
|