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

Barry MacDonnell's
Toolbox for WordPerfect

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

Page updated Dec 6, 2015

WordPerfect Tips
Main tips page | Browse tips

Merge tips


•  Basic information and resources

•  Merging to subdivided pages

•  Sorting and converting existing merged address labels

- Sort address labels by last name (surname)
- Sort address labels by ZIP code

- Convert existing labels to a table

- Convert existing labels to a merge data file (.DAT)

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

•  Converting merge data files (.DAT) to WordPerfect tables or comma- separated- values (.CSV) files

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

•  Workarounds for disappearing bookmarks in merges

Automatically number table rows (or items) when you merge into a table

•  Using a keyboard merge

•  Converting merge codes to text - an external link to a thread on WordPerfect universe; the macro there is useful to display or print a form file and its merge codes in plain text (Note: to convert regular format codes (bold, italics, etc.) to text equivalents see Codes2Txt)

Related pages

•  Converting text to a table -and - converting a table to text or to a merge data file.

•  More on using tables: see here.

[Note that the following menu choices refer to the <WordPerfect> menu (right-click on the top menu bar for a choice of menu). If you use a <Microsoft Word> menu, the choices might be absent from your menu (but not from the program), or they might be found under another menu selection. See here for more.]

Basic merge information (and some resources)

Online (peer) support
The Macros & Merges Forum at WordPerfect Universe can help you find answers to many of your merge questions. (Free to join.)
Tutorials and other help
•  See the Corel Tutorial, Setting Up a Mail Merge, by Laura Acklen. Topics: Building the data file; setting up the form file; merging the files; creating envelopes during a merge. Basic information, but useful for newcomeDAT

•  To use a spreadsheet or table 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 (also a 555KB PDF file here). 

•  In WordPerfect the source of data for the merge is called (generically) a "merge data file."

It can be -

◦  a WordPerfect merge data file (see examples in the sections below),
◦  a WordPerfect table (i.e., a document containing a table with the source data),
◦  the WordPerfect address book,
◦  your own keyboard input,
◦  a database file from another application,
◦  an ODBC data source,
◦  an ASCII Delimited Text file,
◦  a spreadsheet file (as in Doug's article), or
◦  a file in another word processor format.

Hence, you can use any of these types of merge data file as the source instead of a spreadsheet in the first step of Doug's article.

You can, of course, merge to things other than mailing labels. But note that each mailing label is considered a "logical page" as described in the left sidebar on this page, so you should review Doug's article when setting up the merge form for mailing labels.

•  To fill in a form document with a "keyboard merge" see here.

•  To merge certain data records into (rather than from) a WordPerfect table, whereupon each chosen data record becomes a row in the table, see your WordPerfect's Help (F1). (For example, in WordPerfect X6, search the Index for "merges," then "table creation". Other WordPerfect versions should be similar.)

See Footnote 3 for the step-by-step procedure (taken from WPX6's Help) to set up the merge-into-table.

Also see below for methods to number the table rows during a merge.

•  To convert an entire data file into a WordPerfect table, see "Converting merge data files..." below.

•  Various aspects of a merge can be automated with embedded macro commands. (See below. Also see the Macros & Merges Forum on WordPerfect Universe.)

•  Merge programming commands: See your WordPerfect's Help (F1) and search the index under "merge," "merging," "merge codes," "merge programming commands," etc. Usually there are examples given of the various commands.

•  Visit the Macros & Merges Forum on WordPerfect Universe. (Free to join.)

•  There are several other sources on the Internet. Some deal with WordPerfect for DOS; most are for the Windows versions.

The basic merge feature has not changed, so you might gain some knowledge from them. [Example: "WordPerfect Mail Merge," a course-work document from the University of Waterloo. (it is a PDF file here.) Written for WordPerfect version 8, it should still be useful.]

•  See sidebar at left for more tips and techniques.
•  You might find it worthwhile to purchase an after-market book on WordPerfect. They usually have a section on merges. Laura Acklen and Read Gilgen have published several such books. Even if one is not available for the most current version of WordPerfect, an earlier version might still be useful since the basic feature and various merge methods have not changed.

•  There is at least one advanced merge programming book on the Internet: WordPerfect Advanced Merge Handbook, by Julie Jeppson. The WordPerfect programming language should be the same in WPX4 as in WP12, the last version the book was written for.
Links on this site
◦  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

Merging to subdivided pages

If you want to merge data to a form that is printed on a subdivided page -- e.g., a page that is divided in half (or some other fractional amount), to create two (or more) forms per sheet -- then you can try one of these methods.

There are at least three ways to do this.

Method A: Insert the merge command, PageOff, at the very top of the form document to eliminate the hard page code [HPg] between copies of the form file in the merged document. Put your merge codes on the form and merge the data. If your form has several pages and contains hard page breaks, you may need to use PageOn. See WordPerfect's Help (F1) and search for "merge commands."

If this doesn't work, try this method:

Method B: Use the Label definition, Avery 6876, at the top of the form. This creates a physical page divided in half horizontally, producing two sections that are in horizontal format. Of course, you can use ordinary paper instead of label stock when you merge to the form, then shear the paper into sections. Put your merge codes on the form and merge the data. [Note that the sheared sections will be slightly asymmetrical, so you may need to adjust the spacing between labels by editing the label definition. Or, simply use Method C below and create a custom definition from scratch, which is quite easy to do.]

Or try this:

Method C: Create a custom two-column (or two-row) label definition. Then WordPerfect will see the second half of the physical sheet as just another type of label, similar to a sheet of address labels.

Example using letter-size pages in landscape orientation, with two forms per sheet.

Instead of subdividing the page with Format,Page, Page Setup, Layout, you can create your form as a half-sheet size "label" with Format, Labels, Create. When the Create Labels dialog opens:

First, give the new "label" a description; then you will be able to use the Change button to set the sheet size to 11" wide by 8.5" high (here we are assuming landscape orientation).

Set the label size to fit on half the sheet -- perhaps 4.5" wide by 7.5" high.

Set the labels per page at 2 column, 1 row (again, assuming landscape orientation).

You might have to edit the spacing around and between "labels," etc. Start with, say, 1.0" between label columns and an appropriate amount from the top and left edge of the physical sheet of paper, such as 0.5" each.


InkJets might require larger areas around the labels for the rollers to grab the paper.

You might not need page margins as you probably would with address labels, since this type of form already has space outside the label areas. If you do want them here (or on address labels): For some versions of WordPerfect, you might need Charles Rossiter's MarginSet macro (in a Zip file here) if you have problems setting page margins in the Create Labels dialog or in the master label itself.

Then in a new, blank document use Format, Labels to select the new label definition.

Put your merge fields on the form. If you use hard page breaks ([HPg]) in the form you will need to use PageOff as explained above.

Merge the data.

Up arrowPage Top

Sorting and converting existing merged address labels

Whether you have already merged a data file to create a document with address labels, or you have cut-and-pasted addresses directly 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.


The sorting methods below can be used on a list of names just as they can be used on a document full of previously merged labels. A main requierment is that each name (or name and address) is separated by two hard returns or by hard page breaks so that the sort sees them as separate paragraphs. See the first method for more information.

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.


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 also 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 press Ctrl+hyphen in the Find field, and press 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 or exporting the table in .CSV (Comma Separated Values) format -- here's a way to do it.

The procedure is a bit more involved than a simple label sort but it may be worth the effort if you have several hundred labels to sort.


The procedure below converts each line of text in a label into a separate table cell. Each row of the table then will contain the contents of one label. The individual lines of data in each cell can then be used in a merge.

On the other hand, see Footnote 1 for a macro that will copy each entire label (e.g., address labels) as a block of text into a separate table cell. This might be useful (for example) in exporting the table to Microsoft Word where it can be used to print on blank label sheets. 



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

•  Open Reveal Codes to help you see what is happening.

Step 1. You will need to convert your label document to a document where each complete label (called a "logical page") is converted from several separate lines (i.e., name, address, etc.) into a single line, where each of the original lines is now separated by a tab code ([Tab]) rather than a hard return ([HRt]), and where the hard page break ([HPg]) is converted to a hard return.

For example, a label like this (as viewed in Reveal Codes) -

John Smith[HRt]
123 Main St.[HRt]
Anytown, OR 99999[HPg]

- would be converted to this -

John Smith[Tab]123 Main St.[Tab]Anytown, OR 99999[HRt]

Once you do that, all your labels will be strung together is such a way that they can be immediately converted to a single table by WordPerfect.

Step 1a. Prepare the document.

In preparation for this, you will need to remove all left tab [Left Tab] codes from your current labels document, so as not to confuse WordPerfect.

Here's how:

Step 1b. A 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.

[Note that for some codes you have to scroll down quite a bit to find the exact code you need.]

Back in the Find and Replace dialog, click in the "Replace with" field and delete anything in that field. Click Replace All.

Step 1c. 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.

Step 2. Delete the [Labels Form] code from the top of page 1.

Just drag the [Labels Form] code out of the Reveal Codes window, or use the Delete or Backspace key to remove it. (You can delete the [Paper Sz/Type] and other top-of-the document codes 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.

Step 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. (You will need to scroll down to find this code.)

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.

Step 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.


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.

Step 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 Table, Convert (or Insert, Table in earlier versions of the program).
3. Enable one of the following buttons:

· Tabs (or Tabular Column) converts tabular text into a table
· Parallel Column converts parallel columns into a table"

Step 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.

Step 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, etc.


☼  You can convert 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."

☼  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 Table, Convert, Tabs (or Insert, Table, Tabular Column), OK.

☼  You can convert a table to a Comma Separated Values (.CSV) format for imported into other programs. Just place the cursor in the table and do Table, Convert, Convert tables to text: Separate text with commas.

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


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 (you can just select the code in the Find field, then copy it to the clipboard), move the cursor back in front of (i.e., to the left of) that 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:


  • 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:


  • 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:


  • 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:

12 Ash Street
Anytown, OR 99999

John Doe
34 Oak StreetENDFIELD
Anytown, OR 99999


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, as well as the tutorials above.

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:


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

  • 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 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.


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

  • [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.


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

[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 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 A.

(1) If the data file is not already in table format, convert it to a table using the tips above.

(2) Delete all columns except the one you want to process.

(3) Process the column -- perhaps by using Edit, Find & Replace, or with a macro.

(4) Select this edited column and copy it to the clipboard.

(5) 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.

(6) Paste the edited column into the table.

(7) Delete the old column.

(8) If desired, convert the data table back to a text data file using the tips above. [Thanks to Karen Fiorello for this tip.]

Method B.

Use a merge to generate a new data file (.dat):

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.
Thanks to Noal Mellott at WordPerfect Universe for this tip, which is demonstrated here.

[For more on this or other merge programming commands, See WordPerfect's Help file or the Macros & Merges forum at WordPerfect Universe. ]

Up arrowPage Top

Workarounds for disappearing bookmarks in merges

☼  Here's a tip from Lorna Cattell in a WordPerfect Universe post ("Workaround for disappearing bookmarks in merges"):

"Have you ever created bookmarks in a merge form file, only to find that they disappear after the merge is performed?

There are some good reasons for creating bookmarks during a merge, particularly if your merge is for document assembly. For example, you might have macros to run later that depend on finding a bookmark for inserting text in the correct position.

Unfortunately, this disappearing trick is "working as designed", the reasoning (I believe) being that since duplicate bookmarks (i.e. with the same name) cannot exist, duplicates could be created during a merge. This, of course, completely overlooks merging for document assembly where there is no data file to merge.

Happily, though, there is a simple solution using the EmbedMacro command:

In the form file, with the cursor where you want a bookmark:

In the merge toolbar click on MergeCodes, scroll to and insert an EmbedMacro command and include this macro command between the brackets: BookmarkCreate ("XXX")

So, for a bookmark named, say, Accounts, you will have

    EMBEDMACRO((BookmarkCreate ("Accounts"))


[If this doesn't work in your situation, try the next tip:]

☼  From Noal Mellott on a WordPerfect Universe thread ("Merge deletes bookmark"):

[Note: Essentially, the method takes your original "merge form" and inserts it into another merge form file (.FRM) during the merge. This second form file contains (for example) just the macro commands to process the bookmarks contained in the first file. Put another way, the second form file encompasses the first form file during the merge, preventing the creation of duplicate bookmarks as discussed in the previous tip above. For an example of the method see this post on WordPerfect Universe.]

"The DOCUMENT() command provides a way to retain bookmarks.

This command inserts the file named in its parameter into the merge like an ordinary document. If the file is a form file, it is not processed, and any merge codes it contains will be passed on to the merge output.

By the way,
DOCUMENT(C:\Documents and Settings\My Documents\test.frm)
it is the equivalent of
EMBEDMACRO(FileInsert("C:\Documents and Settings\My Documents\test.frm"))

Each inserts the designated form file without processing its commands. Notice, however, that the first takes no quote marks!

To its advantage, the inserted document brings [retains] its bookmarks, whence a way of having the merge output retain bookmarks. ..."

[Note: The DOCUMENT() command is more often used to assemble various parts of the merged output document. ("Document assembly") It might be a good idea to explore using the above method -- a form file with just the commands needed to assemble the document.

From the Help file in WordPerfect X6:

Use DOCUMENT to insert the named document into the merged document at the DOCUMENT command. The document is not processed as a merge file, so any merge commands in the inserted document are included in the file but not executed. This command is commonly used for inserting variable paragraphs in contracts and similar documents (often called document assembly) or for building a form or data file.

In the following example, DOCUMENT inserts the document called oneroom.mrg in the merged document if the variable rooms is equal to 1, or it inserts the document tworooms.mrg if the variable rooms is not equal to 1.

CHAR(rooms;Enter the number of rooms (1 or 2); Number of Rooms)

Up arrowPage Top

Automatically number table rows (or items) when you merge into a table

You can automatically number table rows (or items in column cells) sequentially when you merge data into a table. There are several ways to do it: with a counter, a formula, or a macro.

Method A.

You can do it by inserting a WordPerfect counter in any cell in the merge form's table that contains the NEXTRECORD() command. (This is the "merge fields row," which is duplicated for each record to be merged from the data file.)

This could be used to automatically number the cells in the first column (e.g., "Item #") or any other column (e.g., "Description," etc.) during the merge of data into the table.

Basic technique: See Using WordPerfect Counters. Be sure to note the order of insertion of the two components of the counter.

For example, suppose you have a merge form that uses a WordPerfect table with various cells and merge fields, something like this (first row is a title row):
Case Number
File No. Note
[CountDisp][CountInc] Field(Case) Field(File) Field(Note) Field(Comments)

Here, the counter codes are shown in blue for illustration only. You will actually see them in Reveal Codes in the table (not in the main document window), once you create the counter as described in
Using WordPerfect Counters.


(1) Counters are easy and simple to set up. Creating and inserting the counter codes takes only a minute or two.
See Using WordPerfect Counters.

(2) The counter codes can be placed inside any cell in the merge fields row, even if the cell contains merge codes. (In the above example they are placed before the Case field in the first column, followed by a space -- but they could be placed before or after any merge field in any cell.)

(3) You can add text characters before and/or after the counter (a period, colon, space, brackets, a text label, etc.).

(4) The cell can even have its Numeric Format set to Text and it will still increment the counter during the merge.

(5) The counter should not interfere with any chained macro you might use (with the CHAINMACRO() command).

Method B.

You can do it using a table formula in
any cell in the merge form's table that contains the NEXTRECORD() command. (This is the "merge fields row," which is duplicated for each record to be merged from the data file.)

Basic technique:

In that cell, right click and set the Numeric Format to General or Integer.

Use the main WordPerfect menu and click Table, Formula Toolbar to display the Table Formula property bar (or right-click in that cell and make the same choice). In the toolbar's blank field, type (without quotes) "+ROW()-1" (assuming the first row is a header row and the cursor is in the second row, and want to start with the number "1"; it might help to experiment with the starting number).

Click on the blue checkmark button to insert the formula in the cell. The number "1" should appear. Subsequent cells (if any) in that column should be numbered sequentially when the form is merged.

Advantages and disadvantages:

(1) Note that even though this method is as easy as Method A, it requires the initial ("seed") cell's Numeric Format to be set to General or Integer, and not Text.

(2) As with Method A, you can have prefix or suffix characters added to the numbers, but the formula in the initial cell will be a bit more complex than the example given above ("+ROW()-1"). 

For example, to add the prefix word "Item" plus a space to the numbers (here, you should retain the quote marks around the text characters): +CONCAT("Item ",TEXT(ROW()-1)).

(3) This method can also be used with
the CHAINMACRO() command).

Method C.

You can do it by using a chained macro with the CHAINMACRO() merge command.

Basic technique: See Footnote 2.

Advantages and disadvantages:

Note that this method (which was posted here before the other methods) is often not as simple and easy to do as other methods, and it does not have the advantages cited for Methods A and B. However, it is included here (in Footnote 2) because chained macros can have other purposes -- such as forcing a calculation of the table after data has been merged into it, cleaning up areas of the form, etc. -- and which also could be used along with the counter or table formula methods.


  • You could use the above table example to create an Invoice.

    To do it you can simply add a row below the merge fields row, that should contain a Total cell with a formula (in the Cost column) to sum the cells above it in the column. 

    Typing (without quote marks) "++" as the formula for the Total cell should do the job.

    You could also use CHAINMACRO() to play a macro to force the recalculation of the table with just these two commands: 

  • You can use both Method A and Method B in the same merge form.

Up arrowPage Top

Footnote 1

Copying complete address (or other) labels into a table

The procedure above, Convert existing address labels to a table,
converts each line of text in a label into a separate table cell. Each row of the table then will contain the contents of one label. The table can then be sorted and/or further processed to create a merge data file.

On the other hand, the macro below
should create a new document from one composed entirely of WordPerfect labels (i.e., it will have a [Paper Sz/Typ] and [Labels Form] code at the very top) into a new document composed entirely of a normal WordPerfect table. It does this by copying the entire contents of each label into its own separate table cell in a new document.

This might be useful in exporting the table to Microsoft Word. (You probably will need to tweak the format of the table's font size, row and column margins, etc., so that it will fit the new label sheet.)

As noted above, you can also sort the table and/or convert the table to a standard WordPerfect merge data file very easily. To convert it: 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."

Tested in WPX6 with about 60 normal, unformatted address labels. 

NOTE: The first command in the macro (vCols:=) should be set to the desired number of columns in the table -- usually, 3 or 4. (It is currently set to 3.) The macro will figure out how many rows are needed.

[To copy this macro into your WordPerfect see here.]


Put the cursor anywhere on the labels and play the macro. The screen will flicker a bit since the macro needs to go back and forth between documents to copy the label text into the table cells.

Additional formatting might be needed on the resulting table (font size, column and row margins, etc.).

// Macro code begins
// Converts a document made up of WP labels into a WP table.
// Additional formatting might be needed on the resulting table
// (font size, column and row margins, etc.)
// NOTE: Specify the number of table columns desired:
    MessageBox(;"Too Many Open Documents (9)";
    "At least one available document 'slot' is required."+NToC(0F90Ah)+
    "Close one or more open documents and try again.";IconStop!)
    MessageBox(;"Current Document is Blank";
    "This macro requires text that can be processed.";IconStop!)
// Convert the labels to a WP table:
// Store the current document's number:
// Store the number of pages (labels):
// Open a new document:
// Store the new document's number:
// Create the table:
vTotalRows:=vTotalPages/vCols  // (number of rows needed)
///QuickmarkSet  // ("mark" the current cell)
ForNext(vIndex; 1; vTotalPages; 1)
    // Go back to the original document:
    // Copy the entire label's text:
    If(StrLen(?SelectedText)=0)  // (prevents an error)
        Type(" ")  // i.e., one space character
    EditCopy  // Copy selection to clipboard
    // Go to the table document:
    // Paste the label's text into the table cell:
// Macro code ends

Footnote 2

Merging into a table and automatically numbering the rows

Note: See the calling section above about using WordPerfect counters or table formulas. Those methods are easier and simpler to produce automatic numbering than the technique below, which was posted here earlier. However, using a macro can have other purposes, such as forcing a calculation of the table after data has been merged into it, creating Bates numbering (see the QwikFill macro code), etc., so it was decided to retain the following material, which might be helpful in some other way.

Here is a macro (based on the QwikFill macro) which can automatically add consecutive numbering in the first column of a table in a merge form.

For example, suppose you have a merge form that uses a WordPerfect table with various cells and merge fields, something like this
(first row is a title row):
Case Number File Number Note

Field(Case) Field(File) Field(Note) Field(Comments)

In the merge form you can use a macro like the one ("numbering.wcm" -- see macro code below) to do the column numbering. You would use the CHAINMACRO() merge command to start the macro at the end of the merge (if the merge terminates normally). It will then add the incrementing numbers in the empty cells in the first column.


1. In our example merge form above, the chained macro is named numbering.wcm and it is saved in the user's default macro folder (specified in Tools, Settings, Files, Merge/Macro). It can be any name, as long as it is the same name as used in the CHAINMACRO() command.

2. See the comments in the macro code below. If you wish to make further modification to the macro's operation you can examine the code in the
QwikFill macro for some ideas.

3. If you are merging to a form that has additional material outside the table structure, the cursor would not normally be inside the table when the data is merged. Therefore, you should use the optional command below, PosTableCell("Table A.A1"), to position the cursor inside the table. In our example it's assumed you will be merging to Table A. If it's another table such as Table B, use that table's name instead (i.e., 
PosTableCell("Table B.A1")).

You could use some code in the macro to first find a pre-existing bookmark inside the table and position the cursor there (e.g., anywhere in the top row).

4. Numeric format: The blank cells where numbering will be inserted should have their Numeric Format set to General, and not (e.g.) to Text. Otherwise the macro command TableDataFill will not work as expected to fill the column with incrementing numbers.

5. Suffix characters: It seems that the merge function does not like periods (full stops) as a suffix to the numbers. Use a colon or some other character in the vSuffixChar variable below. (This issue does not arise when using the QwikFill macro on a regular table.)

[To copy this macro into your WordPerfect see here.]

// Macro code begins
// This macro assumes the first row in the table

// is a "title" row of text labels, and the macro
// will populate the first column with incrementing
// numbers starting in row #2, using the
// initial number stored in the vStart variable.
// The suffix character(s) -- here, a colon, stored
// in the vSuffixChar variable -- can be changed and

// even omitted by setting vInsertSuffix:=0.
// Optional choices -
// Turn ON the option to add a suffix to number (1=On, 0=Off):
// Store the desired suffix (N.B.: periods/fullstops don't work):
// Macro processing begins here -
// Get number of table rows whose first cells are to be filled:
// First, position the cursor: If it might not be in the table, use
// the next command to position it in Table A (assuming it should
// be inside Table A and not some other table) by deleting the
// preceding slash marks:
//PosTableCell("Table A.A1")  // (Optional - see Notes above)
// Then, get the total number of rows (minus 1):
// Set the starting number value -
// Begin processing the table column -
// First, "seed" the numbering sequence -
PosTableBegin  // (go to cell A1)
PosTableCellDown  // (go to row #2)
Type(vStart)  // (type the first number)
If(?Row=vRows+1)  // (test if in last row; if so exit macro)
    Return  // (or use Quit)
Type(vStart+1)  // (type the second number)
// Go back to first numbered cell -
// Populate the cells -
PosTableCellTop  // (i.e., beginning of cell)
// Select the rest of the column -
SelectOn (CharMode!)
RepeatValue (vRows)
// Fill the column with incrementing numbers -
TableDataFill  // (same as "QuickFill" command)
// Optional: Go to table top left cell -
// Optional: Add a suffix to numbers, such as
// colons or other punctuation specified above -
    PosTableCellDown  // (go to row #2)
    ForNext(i; 1; vRows-1; 1)
    PosTableBegin  // (Optional: Go to table top)
Return  // (or use Quit)
// Macro code ends

Footnote 3

[Continued from "Basic merge information" above:]

[See also Footnote 2 above for a way to automatically number the table rows.]

From WPX6 Help (F1), "To create a table [from] a merge" (annotated):

1. Click Tools > Merge.

2. In the Merge dialog box, click Form document > Create form document.
If there is text in the active document, enable one of the following options in the Data file source dialog box:

• Use file in active window — uses the active document
• New document window — creates a new document

3. In the Associate form and data dialog box, enable one of the following options and click OK:

• Associate a data file — specifies the path and filename for the associated data file
• Associate an address book — specifies an address book
• Associate an ODBC data source — lets you select an ODBC source
• No association — does not associate any data file

4. On the WordPerfect menu bar, click Table > Create and in the Create table dialog box, type the specified values in the following boxes:

• Columns — number of columns
• Rows — 2

5. Click Create, and type a heading in each cell of the first row.

6. Right-click the table, click Format, and on the Table tab, enable the "Insert new rows automatically" check box, and click OK.

7. Insert fields [i.e., FIELD() merge codes] in the second row of the table, and click Close.

8. Click at the end of the last cell in the second row [i.e., after all codes in that cell], and on the Merge toolbar, click "Insert merge code" and choose More.

9. In the Insert merge codes dialog box, choose REPEATROW from the Merge codes list, click Insert, and click Close.

- - -

- After merging, the table expands one row for each record in the associated data file.

- Press Tab to move to the next cell.


- See also the merge commands NEXTRECORD, PAGEOFF/PAGEON, ONERROR (and other merge and/or macro commands that may be revelant).