A while back, a colleague of mine asked how they could print envelopes with the POSTNET barcode on them. It turns out that Microsoft Word doesn't make this a simple process. So, I decided to write a macro to do this for them. I thought I would share it.
I've pasted the macro VBA code in blue below for you to copy into your own macro module. To use the macro, highlight the recipient's address in your document and run the macro. It will then ask you to type in the zip code. It will then print both your letter and an envelope with the POSTNET barcode on it.
As a note, please remember that I am an attorney and am entirely self-trained when it comes to programming. So if you see the code and cringe, I'd welcome any feedback on how it could be improved.
' Joshua Goodwin
' Adds an envelope and POSTNET barcode to document
' Define and fill Variables
Dim strZipCode As String
strAddress = Selection.Text
strZipCode = InputBox("What is the Zip Code?")
' print letter
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentWithMarkup, Copies:=1, Pages:="", PageType:= _
wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
' Create envelope and add to document
ActiveDocument.Envelope.Insert Address:=strAddress & "**"
' Find location to insert barcode
Selection.MoveRight Unit:=wdCharacter, Count:=2
' insert barcode
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"BARCODE \u" & strZipCode, PreserveFormatting:=True
' Print envelope
' Delete envelope from document