Recently I was talking with my friend Chuck about features he wishes Microsoft would add to Outlook. One of the items on his list is the ability to print an envelope from a contact. Chuck noted that the only two ways he knows of to do this now is to either do a mail merge, which isn’t practical for printing a single envelope, or to copy and paste the contact’s address into Word. Copying the address may be simpler than setting up a mail merge, but it’s still too time consuming. Although I rarely use postal mail myself I can see how this could be useful for those that do. Time to do some scripting.
At 27 lines the resulting script is surprisingly short. That’s largely due to how easy Microsoft has made it to print an envelope from Word. Here’s how it works. The script starts by looking to see if you have an item open or just have one selected. Next, it checks to see if that item is a contact. If it isn’t then the script displays an error and exits. Otherwise, it gets the default address of the selected contact, launches Word, creates an envelope, adds the contact’s address, adds your return address (which you define in the script), and prints the envelope. Simple stuff.
Hopefully this script will make Chuck’s work a little simpler, faster, and more efficient.
This solution should work in Outlook/Word 2007 and later. It may work in earlier versions too, but I haven’t tested with anything older than 2007.
Instructions and Code.
1. Start Outlook
2. Press ALT+F11 to open the Visual Basic Editor
3. If not already expanded, expand Microsoft Office Outlook Objects
4. If not already expanded, expand Modules
5. Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
6. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
7. Edit the return address at the top of the code just below the comment
8. Click the diskette icon on the toolbar to save the changes
9. Close the VB Editor
Sub PrintEnvelope() 'On the next line edit your return address. Use /n to indicate the end of a line. Const RETURN_ADDRESS = "David Lee/n101 Main Street/nHometown, USA 10101" Const SCRIPT_NAME = "Print Envelope" Dim olkCon As Object, wrdApp As Object, wrdDoc As Object, strAddress As String Select Case TypeName(Application.ActiveWindow) Case "Explorer" Set olkCon = Application.ActiveExplorer.Selection(1) Case "Inspector" Set olkCon = Application.ActiveInspector.CurrentItem End Select If olkCon.Class <> olContact Then MsgBox "You must select a contact in order to use this macro.", vbCritical + vbOKOnly, SCRIPT_NAME Else strAddress = olkCon.FullName & vbCrLf & olkCon.MailingAddress Set wrdApp = CreateObject("Word.Application") Set wrdDoc = wrdApp.Documents.Add With wrdDoc.Envelope .Insert Address:=strAddress, ReturnAddress:=Replace(RETURN_ADDRESS, "/n", vbCrLf) .PrintOut End With wrdDoc.Close False End If Set olkCon = Nothing Set wrdDoc = Nothing Set wrdApp = Nothing End Sub
Using the Macro.
1. Select or open a contact. The contact can be in any contact folder.
2. Run the macro. The envelope will print on your default printer.
Adding Buttons to Run the Macro with a Single Click
If you want to be able to run the macro with a single click, then you’ll need to add a toolbar button for Outlook 2007 or a button on the Quick Access Toolbar (QAT) for Outlook 2010.
Outlook 2007. Follow these instructions to add toolbar buttons that runs the macro.
Outlook 2010. Follow these instructions to add the macro to the QAT.