Word.Tips.Net Welcome toWord.Tips.Net

Helpful Links

Tips.Net Home
WordTips Home

Ask a Word Question
Make a Comment

Tips.Net Store

WordTips FAQ
WordTips Premium

Learn Access Now
Free Printable Forms

Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips

Advertise on the
WordTips Site

Newest Tips

Arranging Document Windows

Specifying a Backup Location

Controlling Chart Gridlines

Merging Table Cells

Collapsing and Expanding Subdocuments

Zooming With the Keyboard

Initiating a New Search

 

Printing Personalized Copies of a Document

Summary: Need to have a series of documents customized for individual users? Mail merge may be overkill, but the macro presented in this tip will help make short work of the individualized printouts. (This tip works with Microsoft Word 97, Word 2000, Word 2002, Word 2003, and Word 2007.)

Mahmud asked for a way to print personalized copies of a document. He started with a list of names in a regular text file, one per line, and he wanted to print one copy of the current Word document for each of those names. Further, he wanted the person's name placed in the header of the document.

The process to perform such a task is fairly straightforward: open the text file, grab a name, put it in the header, and then print the document. Another name is grabbed, and the process is repeated until there are no more names in the file. The following macro implements such a process:

Sub PutNamesInHeader()
    Dim sName As String

    Open "c:/names.txt" For Input As #5
    Do While Not EOF(5)
        ' get the name
        Line Input #5, sName

        ActiveWindow.ActivePane.View.SeekView = _
          wdSeekCurrentPageHeader
        Selection.WholeStory
        Selection.Delete
        Selection.TypeText Text:=sName

        ActiveWindow.ActivePane.View.SeekView = _
          wdSeekMainDocument
        ActiveDocument.PrintOut
    Loop

    Close #5

    ActiveWindow.ActivePane.View.SeekView = _
      wdSeekCurrentPageHeader
    Selection.WholeStory
    Selection.Delete
    ActiveWindow.ActivePane.View.SeekView = _
      wdSeekMainDocument
End Sub

The tricky part of the macro is using the .SeekView property to specify which story in the document you want to work with. As implemented here, the .SeekView property is used repeatedly to switch between the header area and the main document. After the loop (grabbing names and printing) is completed, the header area is cleared and the .SeekView is switched back to the main document.

Tip #152 applies to Microsoft Word versions: 97 | 2000 | 2002 | 2003 | 2007

Great Idea! Word is a tool to get what you really want—printed output. This means you need to make sure that Word works as well as possible with your printer, whether it is sitting on your desk or in a room down the hall.
 
Check out WordTips: Printing and Printers today!