Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map

Barry MacDonnell's
Toolbox for WordPerfect

Macros, tips, and templates for Corel® WordPerfect® for Windows®
© Copyright 1996-2008 by Barry MacDonnell. All Rights Reserved.

Page updated June 30, 2008
WordPerfect Tips
Main tips page | Browse tips

Merge tips

Basic information and resources

Online (peer) support

  • The Macros & Merges Forum at WordPerfect Universe can help you find answers to many of your merge questions.

Tutorials

  • See the Corel Tutorial, Setting Up a Mail Merge, by Laura Acklen.
  • To use a spreadsheet as the source for a merge, see Doug Loudenback's Using WordPerfect's merge to create mailing labels from a Quattro Pro (or Excel) spreadsheet file (a 555KB PDF file here).

Books

  • You might find it worthwhile to purchase an after-market book on WordPerfect, such as those on the home page here.

Links on this site

  • Merge tips for multi-page documents - includes:
    • setting up different printer trays for the first (usually: letterhead) page and subsequent pages (see also next link below for more details);
    • resetting page margins and page numbering for each merged document; and
    • forcing each multi-page merged documents to start numbering with page "1".
  • Multiple trays: Print your letterhead page from one printer tray, and second and subsequent pages (or envelopes) from another tray or slot

Up arrowPage Top

Sorting and converting existing merged address labels

Whether you have merged a data file to create address labels, or you have cut-and-pasted addresses into address labels, you can sort them or convert them to either a WordPerfect table or a merge data file. There are several ways to do this.

Sort address labels by last name (surname)

You can use this method suggested by Seth Katz at WPuniverse. It sorts labels directly, based on surname, using the paragraph sort option of the Sort feature.

Note: If some labels contain suffixes (e.g., John Smith, PhD) this method will work if you first "glue" all suffixes to their adjacent surnames with a hard space. You can do this manually for each label with <Ctrl+Space> or do it globally for all labels with Find and Replace. For example, you could use Find and Replace to find every " PhD" (i.e., space+characters) and replace all instances with "[HSpace]PhD".

(The [HSpace] in this example represents the actual binary code you need to enter in Find and Replace's "Replace with" field using the Find and Replace menu items, Replace, Codes....) [Thanks to Jan Berinstein for this tip.]

  • Always make a backup of your file before following this procedure.
  • First, be sure that all labels contain at least two hard returns ([HRt]) or they end with a hard page break ([HPg]). [Hard page breaks can be entered with <Ctrl+Enter>.] Two hard returns or a page break define a "paragraph" for the sort tool.
  • Then click on Tools, Sort, New. In the "Sort Description" field, enter a name (e.g., "Sort labels by surname").
  • Click the Sort by Paragraph radio button.
  • Under "Keys (sorting rules)," "Key 1," enter "-1" (without quotes) in the Word field. If you also want to sort duplicate surnames alphabetically by the person's given name, add another key (Key 2) with a "1" (without quotes) in the Line, Field, and Word fields.
  • You may want to use the Options button to allow undoing the sort.
  • Click OK, then Sort.

Note that the sort will be performed on all labels no matter which label your cursor is in.

Up arrowPage Top

Sort address labels by ZIP code

This is similar to the procedure above. However, it sorts on the last "word" of the third line of each paragraph -- the ZIP code. If your labels do not all have the ZIP code on the third line, the results will be less than optimal. (If the ZIP code is on another line in all labels you can adjust for this below.)

  • Always make a backup of your file before following this procedure.
  • First, be sure that all labels contain at least two hard returns ([HRt]) or they end with a hard page break ([HPg]). [Hard page breaks can be entered with <Ctrl+Enter>.] Two hard returns or a page break define a "paragraph" for the sort tool.
  • Then click on Tools, Sort, New. In the "Sort Description" field, enter a name (e.g., "Sort labels by ZIP code").
  • Click the Sort by Paragraph radio button.
  • Under "Keys (sorting rules)," "Key 1," enter "3" (without quotes) in the Line field and "-1" (without quotes) in the Word field.
    • NOTES:
    • If the ZIP code is not on line #3 of each label (e.g., it is on Line #4) then enter the correct line number for the current Key (i.e., use "4" in the Line field).
    • ZIP codes with more than 5 numbers are usually separated by hyphens (e.g., 99020-0451). For this sort to work properly, all hyphens must have been entered with the hyphen key, which produces a hyphen code ([-Hyphen]) in Reveal Codes. [Not all ZIP codes must have hyphens, however. For example, the sort will work with 5-digit ZIPs mixed in with 9-digit ZIPs.]
      • If the some or all hyphens in the ZIP codes are hyphen characters (-), then before you can sort the labels you will need to convert all of these "hard hyphens" to regular hyphen codes with Find and Replace, as follows:
      • Go to the top of your label document and click Edit, Find and Replace. Press the hyphen key in the Find field, and press Ctrl+hyphen in the Replace field; then use Find Next to locate each one individually and Replace it if it is inside a ZIP code.
      • [Ctrl+hyphen produces a hard hyphen; also, it can be produced in other programs or converted from a regular hyphen by WordPerfect during certain paste operations. For more on the various types of hyphens in WordPerfect, see here.]
  • You may want to use the Options button to allow undoing the sort.
  • Click OK, then Sort.

Up arrowPage Top

Convert existing address labels to a table

If for some reason the above methods do not work, or you want to convert the labels to a table for future use -- such as using them in a merge -- here's a way to do it. It is more involved than a simple label sort, but may be worth the effort if you have several hunded or more labels to sort.

Always make a backup of your file before following this procedure.

(1) You will need to convert your labels to a document where each line (or "field") of every label (i.e., name, address, etc.) is separated by a tab, not a hard return, and where each complete label (called a "logical page") is converted to single line ending in a hard return ([HRt]). Once you do that, your label material will be strung together is such a way that it can be immediately converted to a table by WP.

In preparation for this, first remove all left tabs from your current labels document, so as not to confuse WP. You can use Edit>Find and Replace, and replace all Left Tabs with a space. Here's how:

Recommended option: First remove any [Tab Set] codes by using Find and Replace, replacing them with <Nothing>. This will convert any existing right tabs, decimal tabs, etc., to (default) left tabs before replacing all left tabs in the next step. Here's how: Go to the very top of your document. Click on Edit>Find and Replace>Match>Codes. Choose the Tab Set code from the Codes dialog, and Insert it. Back in the Find and Replace dialog, click in the "Replace with" field and delete anything in that field. Click Replace All.

Replace left tabs: Go to the very top of your document. Click on Edit>Find and Replace>Match>Codes. Choose the Left Tab code from the Codes dialog, and Insert it. Back in the Find and Replace dialog, click in the "Replace with" field and delete anything in that field. Enter a character string or symbol (use Ctrl+W to enter a symbol) that is not likely to be found in your labels document. Click Replace All. Any Left Tabs in your labels should be replaced with this temporary character or symbol.

(2) Next, open the Reveal Codes window. Delete the [Labels Form] code from the top of page 1. (You can delete the [Paper Sz/Type] code if you wish.) This will remove label formatting and return your document to a standard size. Each label should now be on one or more 8.5" x 11" pages.

(3) Replace all hard return [HRt] codes with [Left Tab] codes:

Click on Edit>Find and Replace>Match>Codes. Choose the HRt code and insert it. Back in the Find and Replace dialog, click in the "Replace with" field and delete anything in that field. Click Replace>Codes, and choose Left Tab (but not ...Left Tab), and insert it. Click Replace All. All label text should now be strung together with tabs separating each "field," and each label's data should be on a separate page.

(4) Go to the top of the document. Replace all [HPg] codes with [HRt] codes, using the Find and Replace dialog. All label text should now be on one (or more) page(s), each separated by a single hard return.

Recommended option: Change the page setup to landscape mode to accomodate the new table, which may be very wide. Go to the very top of the document, and click Format>Page>Page setup. Under the Size tab, click the Landscape radio button, then click OK. You may want to reduce the text's font size by entering a smaller value with Format>Font>Size.

Notes: If some of your original labels contained blank lines, the conversion to tabs in Step #1 may cause some address fields to be "offset" horizontally from other records. So, before going to Step #5, you can manually delete these extra tabs (or add tabs where needed in other labels) to properly line up all address fields into their respective columns. In fact, at this point you may want to save the temporary file under a different name, and perform whatever "housekeeping" is needed to line up address fields so that Step #5 will produce a table requiring minimum data adjustments.

If you want to separate data in, say, the name field, into individual components (e.g., first name, last name, title, etc.), you can manually replace spaces with tabs between these items on a row-by-row basis. This can be tedious, but it ensures that you end up with a more useful data file -- especially if you want to sort by last name or some other part of an address line.

(5) Convert the data to a table. Here's how (from WP9 Help):

"...You can convert tabular text or parallel columns into a table format. Tabular text includes text that is separated by tabs, and parallel columns include text that is in column format. For information about parallel columns, see 'Creating and deleting columns.'

To create a table by converting text

1. Select the tabular text or parallel columns.
2. Click Insert, Table.
3. Enable one of the following buttons:

· Tabular Column converts tabular text into a table
· Parallel Column converts parallel columns into a table"

(6) Since you started this process (Step #1) by replacing left tabs with temporary characters or symbols, you can replace or remove these temporary items now. Use Find and Replace and replace them with Left Tabs to return your label text to its original state, replace them with single spaces, or replace them with <Nothing> if you no longer need these tabs. Remember to use Edit>Undo if you don't like the effect of replacing or removing them.

(7) Finally, trim the table of any excess spaces, rows, or columns, and join cells if required, etc. You can then sort the table or use it in a merge.

Note 1: You can covert the table to a standard WordPerfect merge data file very easily. Go to the top of the document, and in the Reveal Codes window, delete the [Tbl Def] code. This will pop up a Delete Table dialog, and you can select "Convert contents to merge data file."

Note 2: Once everything is in a table, you can either sort the table (as mentioned in Step 7 above) and manually delete duplicate rows or remove the table's *structure* (as explained below in "Convert a table to text...") and leave the text behind as tab-separated lines of data. These tab-separated lines -- each ending in a hard return -- can then be processed automatically to remove duplicate lines with my RemDupes macro, included in the Unique.zip archive. After duplicate lines are removed with RemDupes, the remaining tab-separated data can be converted back into a table by selecting the entire list with your mouse (or Edit, Select, All), then clicking on Insert, Table, Tabular Column, OK.

Up arrowPage Top

Convert existing address labels to a merge data file (.DAT) (12/7/01)

This method uses WordPerfect's Find and Replace feature to change an existing file of labels to a merge data file. (You may want to make a backup of your label file first.)

Always make a backup of your file before following this procedure.

  • In the labels document, open the Reveal Codes window and delete the [Labels Form] code at the top of the document. This changes the document to one where each label is on a separate (standard full-size) page.
  • Position the cursor at the very top of the document. Click on Edit, then Find and Replace. With the cursor in the "Find:" field of the Find and Replace dialog, click Match, Codes..., and in the small Codes dialog that pops up, scroll down and select HRt, and then click Insert to insert one [HRt] code in the "Find:" field.
  • Position the cursor in the "Replace with:" field. Insert one HRt code, then check the box "Display merge codes only." Scroll down and select ENDFIELD, then click Insert. The "Replace with:" field should now look like this:

[MRG:ENDFIELD][HRt]

  • Click Replace All in the Find and Replace dialog. When all replacements are made, click OK to dismiss the message (but leave the other dialogs onscreen). Click in the document and position the cursor at the very top of the document so that you can begin the next Find and Replace.
  • Position the cursor in the "Find:" field of the Find and Replace dialog. Delete the [HRt] code you just used and insert a [HPg] code in its place. (If the Codes dialog is not onscreen, click Match, Codes..., HPg, Insert.)
  • Position the cursor in the "Replace with:" field, and add another [HRt] code to the codes already there. The field should now look like this:

[MRG:ENDFIELD][HRt][HRt]

  • Position the cursor between the two [HRt] codes and select ENDRECORD in the Codes dialog, then click Insert. The "Replace with:" field should now look like this:

[MRG:ENDFIELD][HRt][MRG:ENDRECORD][HRt]

  • Click Replace All in the Find and Replace dialog. When all replacements are made, click OK to dismiss the message, and close the Find and Replace dialog.

Your document should now contain merge data records that look something like this:

John DoeENDFIELD
123 Main Street
ENDFIELD
Anytown, OR 99999
ENDFIELD
ENDRECORD

Jane Doe
ENDFIELD
...etc.

Save this data file with a .DAT filename extension (e.g., MyLabels.dat). The data file can now be associated with a merge form and be used to merge letters, envelopes, labels, etc. See WordPerfect's Help (F1) for more information on merging.

Up arrowPage Top

Converting tables to merge data files (.DAT) or plain text (02/06/02)

To convert a table to a merge data file (.DAT) or ordinary text:

  • With the cursor placed anywhere inside the table, click Select Table on the Table Property Bar and select all cells; then click the Table button on the Property Bar, then click Delete. [Tip: A shortcut is to use Reveal Codes and delete the [Tbl Def] code, which will bring up the Delete Table dialog.]
  • To convert to a merge data file, choose one of the "Convert contents to merge data file" options. This converts the table to a file where each row (i.e., record) is a page ending with [ENDRECORD] and each column (i.e, field) ends with [ENDFIELD].
  • To convert to ordinary text, choose "Table structure" from the Delete Table dialog, then OK. This deletes just the table structure, converting the table's contents to ordinary text.

Up arrowPage Top

Converting merge data files (.DAT) to WordPerfect tables or "comma delimited" (a/k/a/ comma-separated-values, or .CSV) files (02/06/02; 12/20/07)

Here's how to convert a traditional merge data text file (.DAT) where each record is a page ending with [ENDRECORD] and each field ends with [ENDFIELD] to a normal WordPerfect table with multiple rows (records) and columns (fields) -- which can also be used as a merge data table file later, if desired.

  • [These steps were tested in WPX3, but should be similar back to at least WPWin6.1.]
  • Make a backup of the data file.
  • Create a merge form with Tools, Merge, Form Document, Create Form Document. Choose the "Associate a data file" button, and then select the data file (.DAT) from the adjacent browse field. Click OK. Click Cancel to remove the Merge dialog.
  • Create a two-row table with as many columns as there are fields in a record in your data file; type the field names used in your data file into the first row. From the Table, Format dialog, under the Table tab, be sure "Insert new rows automatically" is enabled.
  • Place the cursor in the first cell of the second row, then click the Insert Field button on the Merge Toolbar. Select the field name from the "Insert Field Name or Number" dialog (just click the name), then click Insert. You can leave this dialog on screen, and move the cursor to the next field name, and repeat the Insert process. At the end of the row, click Insert Merge Code from the Merge Toolbar, and choose "More..." and then find REPEATROW in the Codes list and click Insert, then Close.
  • Merge the file as you would any other form file. The new document will have a table where the first row contains the field names and the remaining rows contain the merged data.
  • Select the entire merge data file with Edit, Select, All (a shortcut like Ctrl+A may not work).
  • Then click on Table, Create (in WP9 and earlier, use Insert, Table). A "convert" dialog pops up, with several choices such as "Tabs" (or "Tabular column"), "Parallel Columns," "Merge Data File," etc.
  • Make your choices and then click OK. [TIP: You may want to set the document to Landscape (go to the very top and click Format, Page, Page Setup) and also set the page's font size to a very small size before converting the data to a table.]

Here's how to convert a merge data text file (.DAT) to a comma-delimited file (.CSV), a file where each record is on its own line and each field in the record is separated by a comma, and which Microsoft Word -- or almost any program that can import data -- should recognize:

  • Since each merge data file record (except the first) should be separated by hard page breaks ([HPg]), and have the same number of fields, each ending with a hard return ([HRt]), you can -
    • Step 1. Use Find and Replace (on the F&R menu choose Match > Codes > HRt > Insert > Close) to replace all [HRt] codes with a comma.
    • Step 2. Replace all [HPg] codes with a [HRt].
    • Step 3. Search for all the WordPerfect [ENDFIELD] and [ENDRECORD] merge codes, but replace them with <Nothing>. Note that the Codes dialog you used (Step 1 above) has a small checkbox to "Display merge codes only". Enable that box to search for just merge codes.
  • The file will now be a "comma separated values" file. Be sure to save it with a .CSV filename extension.

Up arrowPage Top

Extract table cell data that is not in merge format so it can be used as a merge data file (07/19/06)

There are many possible table formats, so let's use a relatively simple example. Hopefully, the methods will be useful in your own work.

Suppose you have a table with a single column, with data like this -

John Smith
123 Main Street
Portland OR 97229
Mary Jones
456 South Ave
Seattle WA 98110
Bob Black
678 Western Blvd
San Francisco CA 96200

- and so forth.

The problem here -- insofar as a WordPerfect merge is concerned -- is that the table cells contain data that is separated into "fields" with hard returns. That is, each part of each address is on a separate line ending with a [HRt] code. You need fields that are separated with [ENDFIELD] merge codes, and each record ending with an [ENDRECORD] code. So you have to extract the data from the table and convert it to a merge data file.

Here is one way to solve the problem, though it probably will require some editing of the table or data file before you can use it in a merge.

[Note: This works in WordPerfect 10 and later versions:]

First, you need to convert the one-column table (where each cell has a name and address -- names, cities, states, etc., separated by spaces -- and each line ends in a hard return) into a format that can then be converted into a merge data file. You can do this by separating data fields with left tabs.

  • Use Find and Replace, and Find all [HRt] codes (with F&R's Match>Codes) in the table and Replace all of them with [Left Tab] codes (with F&R's Replace>Codes). Each cell in your table should now have its contents all on one line, with each segment (i.e., field) separated by a left tab. (If any data -- such as City/State/Zip -- are separated with spaces, but should be separated by left tabs into separate fields, use Find and Replace to do the job.)
  • Insert a new row at the top of the table and use it for Field names, separated by the same number of tabs as you find in a typical data row. (Use Ctrl+Tab to insert left tabs into a table cell.)
  • Delete the table structure (only) by deleting the [Tbl Def] code, and when the Delete Table dialog appears choose "Convert Table Contents," then choose "Convert tables to text - Separate text with tabs." The data should now be in ordinary text with each line constituting a data record, and with each record's data fields separated by left tabs.
  • To ensure that the data is in the correct columns, select the data and click Table, Create, (choose the number of columns to match the row with the most number of fields; this should be automatically done by WordPerfect), set Table Delimiters to tabs, then click OK. You should now have a table again, with data fields separated into individual columns. (The first row is the fieldname row.)
  • Make any corrections (use cut-and-paste) to your data.
  • Delete the [Tbl Del] code again, click "Convert table contents to" and choose "Convert text to merge data file" and be sure to check the box, "Use text in first row as field names." Click OK.
  • You should now have a standard merge data file.

Up arrowPage Top

How to edit just one field in several records of a merge data file

  • Here's are a couple of relatively simple ways to edit several items in just one field of a data file with multiple records, such as just the ZIP code field. (Make a backup of the file first.)
    • Method 1:
      • If the data file is not already in a table format, convert it to a table using the tips above.
      • Delete all columns except the one you want to process.
      • Process the column -- perhaps by using Edit, Find & Replace, or with a macro.
      • Select this edited column and copy it to the clipboard.
      • Open a copy of the original data file with the table in it, and insert a new, empty column adjacent to the old (unedited) one.
      • Paste the edited column into the table.
      • Delete the old column.
      • If desired, convert the data table back to a text data file using the tips above.
      • [Thanks to Karen Fiorello for this tip.]
    • Method 2:
      • Create a new data file as the merged output of the first data file, using a form file that contains the various FIELD() commands -- but with a MRGCMND in the form file. [For more on this or other merge programming commands, See WordPerfect's Help file or the Macros & Merges forum at WordPerfect Universe. Thanks to Noal Mellott at WordPerfect Universe for this tip, demonstrated here.]

Up arrowPage Top