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 Sep 16, 2016


WordPerfect Tips
Main tips page | Browse tips

Merge tips

Contents:

•  Basic information and resources

•  Merging to subdivided pages

•  Sorting and converting existing address labels
-

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

Convert (extract) existing labels to a table

Convert (extract) 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 for sorting/merging; merging data files into a table; and converting data files to "comma-separated-values" (.CSV) files 

•  Extract table cell data that is not in merge format so it can be used as a merge data file (i.e., cells containing lines of data that should be in separate columns [cells], not all in a single column)

• 
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


Related pages:

•  Using a keyboard merge

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

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

•  More on using tables: see here.

Note

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

•  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 files as the source instead of a spreadsheet (as discussed in the first step of Doug's article).

[Related tip: When formatting "sub" documents that are to be merged or inserted in their entirety into the main document (a.k.a., the merge form), see Gordon McComb's post on WordPerfect Universe here. (A portion of that post is in Footnote 4.)]

You can, of course, merge into 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 the method below (or Footnote 3) for the step-by-step procedure  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.
Books
•  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.

Note

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 address labels

If you have an existing document containing address labels, where each part of the address on each label is on a separate line something like this -

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

- then you can

•  sort them (e.g., by surnames or by ZIP codes);

or

•  convert them to a WordPerfect table (which can be sorted and/or used in a merge);

or

•  convert them to a merge data file.

See the following sections for various methods to use.


Sort address labels by last name (surname)

You can use this method suggested by Seth Katz at WPuniverse. It sorts existing 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.]

Procedure

Always make a backup of your file 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.)

Procedure

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 (extract) existing address labels to a table

If for some reason the above sorting methods do not work, or if you want to convert existing address labels to a table -- perhaps to use them in a merge (see Laura Acklen's tutorial for an example of a table used in a merge) -- or to export the data in .CSV (Comma Separated Values) format, here's a way to do it.

This 7-step procedure is a bit more involved than a simple label sort but it may be worth the effort if you have dozens or even hundreds of existing labels in a label document.

As with many other unfamiliar things, the procedure is faster to carry out than to explain.

On the other hand, if you don't need to convert your address label data to a table (you can always do it later) but you still want to extract and merge the data using WordPerfect -- and you are familiar with the merge data file (.DAT) format -- see the next section. The procedure there is a bit faster to perform, too.

Important notes

¤  The step-by-step procedure below converts each line of text in a label into a separate table cell (a data field) in the same table row. Each row (a data record) of the table then will contain the contents of one label. The data in each table cell in a row can then be used in a merge -- such as to Avery labels or envelopes.

[See the basic merge information section above for general help on setting up merges.]

¤  To use a table as a source of data for a merge, the first row of the table (optionally) contains the field names you will create. [See the example data table in Laura Acklen's tutorial.]

For example, if the first address label in your existing label document looks like this (e.g., 3 lines of text) -

John Smith
123 Main St.
Anytown, OR 99999

- then the first and second data table rows might look like this:

NAME
ADDRESS
CITY-ST-ZIP
John Smith 123 Main St. Anytown, OR 99999

¤  Alternative to separating each line of a label into individual table cells: See Footnote 1 for a macro that will copy each entire label 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.

Procedure

Step 1. You will first need to convert your label document to a document where -

•  each complete label (called a "logical page" as described in the sidebar here) is converted from several separate lines (i.e., name, address, etc.) into a single line of text, and where
•  each of the original lines is now separated by a tab code ([Tab]) rather than a hard return ([HRt]), and where
•  hard page breaks ([HPg]) are removed (replaced by HRt codes).

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]

All the content of your labels will then be strung together is such a way that they can be immediately converted to a single table by WordPerfect.

However, if the labels in the original address file, as viewed in WordPerfect with Reveal Codes open, does not fit the general format of text and codes shown in the above multi-line example (the actual number of lines isn't typically important, it's the format codes that matter), the procedure below might not work.

Step 1a.  Prepare the document.

•  Back up the address label document.

•  Open Reveal Codes to help you see what is happening with various format codes.

•  In Step 1b and Step 1c below, remove certain format codes from the address label document so as to provide a clean conversion to a table.

Step 1b.  Remove any existing Tab Set codes. [A highly recommended option for most users.]

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 and place the insertion cursor before (to the left of) all other codes.

•  From the main WordPerfect menu, click on Edit, Find and Replace.

•  On the dialog that opens,, click on Match, then on Codes.

Dialog with Match > Codes displayed

•  Choose the Tab Set code from the Codes dialog that appears, and Insert it. [Note: For some codes you have to scroll down quite a bit to find the exact code you need.]

Codes dialog with Tab Set chosen

•  Click Close on the Codes dialog to return to the Find and Replace dialog. [You can also just use Insert & Close instead of separately pressing Insert and Close.]

•  The "Replace with" field in Find and Replace should be blank (empty) or just contain the default entry of
"<Nothing>". If it contains anything else, delete the entry. Then click Replace All.

Dialog with Tab Set code and Replace All

If no Tab Set codes are found you will see a message to that effect.

Step 1c.  Remove any existing Left Tab codes - temporarily or permanently.

Why remove them temporarily?

Some address labels in the original file might have tabs ([Left Tab] codes) in them that you might want to retain after conversion of the data to a table format.

Sometimes tabs are used on mailing labels to indent one or more address lines.

The technique below temporarily replaces the tabs with a user-chosen symbol or other text characters not used elsewhere in the label document to temporarily "hide" them from processing. Later (Step 6), it restores these particular tabs by simply reversing the hiding steps.

Hence, you get to keep them in the resulting data table.

Why remove them permanently?

If you don't need to retain any existing tabs that might be on your labels then you can simply use Find and Replace to find all the [Left Tab] codes and replace them with <Nothing> -- in a similar way that you removed all the [Tab Set] codes in the Step 1b above.

Hence, you get to discard them from the data table.

If you decide to remove the existing [Left Tab] codes, in Step 1c below you can simply -

•  perform just the steps under the "Search for [Left Tab] codes" heading below, then press Replace All to remove the tab codes; and

•  skip the steps under the "Replace with characters or a symbol" heading; and

•  when you get to Step 6, skip that step.

Alternatively, if you decide to complete all of Step 1c below you will still have a choice about what to do with those existing (now "hidden") label tabs: In Step 6 you can either restore the tabs that were hidden, or you can just remove the temporary symbols/characters instead of using them to restore the hidden tabs. The latter will simply clean up the document of temporary items (and tabs) before proceeding.

Bottom line:

You must either hide or completely remove any existing [Left Tab] codes before using Step 3 or the conversion of your labels to a table won't work properly!
The conversion requires using new [Left Tab] codes to separate label data for conversion to table columns, so if the program sees any other tabs it will use them as separators, too.


Search for [Left Tab] codes:

•  Go to the very top of your document before all codes and open Find and Replace (if it's not already open).

•  Click on Match, then on Codes. Choose the Left Tab code from the Codes dialog, and Insert it.

[Important: This code differs from similar left tab codes (such as ...Left Tab), and it is quite far down in the list. See the image below for some adjacent codes to help you locate it.]

Codes dialog with Left Tab selected

•  Click Close on the Codes dialog to return to the Find and Replace dialog. [You can also just use Insert & Close instead of separately pressing Insert and Close.]

•  The "Replace with" field in Find and Replace should be blank (empty) or just contain the default entry of "<Nothing>". If it contains anything else, delete the entry.

Replace with characters or a symbol:

[If you haven't already done so, please read the message in the box above before using the next replace-the-code step. You might want to simply remove all existing [Left Tab] codes rather than temporarily hide them with a "nonsense" character string or symbol as the next step does.]

•  In the "Replace with" 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. (Here, some characters from the keyboard were used.) Then click Replace All.

Find and Replace showing replacement

Any [Left Tab] codes in your labels should be replaced with these temporary characters or symbol. If no tab codes are found you will see a message to that effect.

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

•  Just drag the [Labels Form] code out of the Reveal Codes window, or use the Delete or Backspace key to remove it. [You can also delete the [Paper Sz/Type] and other top-of-the document codes if you wish.]

This will remove the label format (page layout) and return your document to a standard size.

Each label should now be on one or more separate full-size pages.

Step 3.  Replace all hard return [HRt] codes with [Left Tab] codes:

•  Place the insertion cursor at the top of the document.

•  Click on Edit, Find and Replace (if it's not already open). Click in the "Find" field and delete anything in that field.

•  Click on Match, then on Codes. Choose the HRt code and insert it in the "Find" field. (Like the above codes, you will need to scroll down to find this code.)

Codes dialog with HRt selected

•  Click Close on the Codes dialog to return to the Find and Replace dialog. [You can also just use Insert & Close instead of separately pressing Insert and Close.]

•  Click in the "Replace with" field and delete anything in that field.

•  While the cursor is in the "Replace with" field click on Replace, Codes, and choose Left Tab (but not ...Left Tab), and insert it.

Codes dialog with Left Tab chosen

•  Click Replace All.

Find and Replace with 2 codes

All label text should now be strung together with tabs separating each "field," and each label's data should be on a separate page full-size page.

Step 4.  Replace all [HPg] codes with [HRt] codes.

•  Go to the top of the document.  Use Find and Replace in the same way as in Step 3 to change hard page breaks ([HPg]) to hard returns ([HRt]):

Find and Replace with 2 codes

All label text should now be strung together with tabs separating each "field," and each label's data should be on a separate line ("record").

•  Recommended options

You can change the document's page setup to landscape mode to accomodate the new table (created in Step 5 below), which may be very wide. Go to the very top of the document, and click Format, Page, Page setup. Click the Landscape radio button, then click OK. You also might want to reduce the text's font size by entering a smaller value with Format, Font, Size at the top of the document.

•  Notes and tips (read all before using)

If some of your original labels contained blank lines, the conversion to tabs in Step #3 may cause some address fields to be "offset" horizontally from other records. So, before going to Step #5:

Manually delete some extra tab stops from the ruler bar -- they are small triangle shaped symbols on the ruler bar; just drag them from the bar -- so that each main tab stops are spaced out somewhat. This should force better vertical alignment of all fields. [The ruler bar is visible when View, Ruler is enabled.]

Then you can manually delete any extra tabs inside records (or add tabs where needed in other records) to properly line up all address fields into their respective columns.

In fact, at this point you may want to save this 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 the data in (e.g.) the name field into individual components (e.g., first name, last name, title, etc.), you can manually replace spaces with tabs between all these items on a row-by-row basis. But remember: These tabs will be used as column separators in Step 5, so you'll need to use the same number of tabs for each record. 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 tab-separated lines of text 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. [Edit, Select, All.]

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 [<- here, this is the choice to make]

· Parallel Column converts parallel columns into a table  ..."

4. Click OK.

Step 6.  If you started this process by replacing left tabs with temporary characters or symbols (Step 1c), 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 -or- replace them with single spaces or with <Nothing> if you no longer need these tabs.

•  Remember you can 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, add needed columns, etc.

•  You can then sort the table (Tools, Sort) or use it in a merge, etc.

If the table is used in a marge you might want to insert a single "field name" row at the top of the table. It will contain your names for the fields (cells) that contain data to merge into various locations in the merge form. (See the brief example at the top of this section.) Just right-click in the first address row and then choose Insert, Rows, (1), Before, OK. Then type the desired field names in that row that will correspond to the fields on your merge form. This can help identify the cells in the table.

Tips

☼  You can convert the table to a standard WordPerfect merge data file very easily. (Some organizations prefer that format.) 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."

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

☼  Duplicate records: Before converting the 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 in "To convert a table to text..." here) 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.

Up arrowPage Top

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

This method uses WordPerfect's Find and Replace feature to change an existing file of address labels to a merge data file by adding certain merge codes to the file and reformatting the file to remove hard page codes between records.

[Further: The data file can be instantly converted to a WordPerfect table (rows=records, columns=fields), if desired. The table can then also be used as a data file. See here.]

Step 1.

•  Always make a backup of your label file first.

•  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 its own, separate (standard full-size) page.

Step 2.

•  Position the cursor at the very top of the document. Click on Edit, Find and Replace. With the cursor in the "Find:" field of the Find and Replace dialog, click Match, Codes.

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

Codes dialog with hard return displayed

Step 3.

You now need to insert two codes in Find and Replace's "Replace with:" field.

•  Position the cursor in the "Replace with:" field and insert a HRt code there.

Notes

¤  If the Codes button is still on screen, just click Insert. If it's not on screen you can just select the [HRt] code in the "Find:" field (see Step 2), then copy it to the clipboard and then paste it into the "Replace with:" field.

¤  The "Find:" field is now renamed by the program to "Replace".

•  Important: Position the cursor in front (i.e., to the left side) of that [HRt] code.

•  Check (tick) the box "Display merge codes only" at the top of the Codes dialog (see image in Step 2). This will change the "Find codes" window to show merge codes.

•  Scroll down and select ENDFIELD, then click Insert, then Close (or just Insert & Close).

The "Replace" and "Replace with:" fields should now look like this:

Find and Replace with EndField code

Step 4.

•  Click Replace All in the Find and Replace dialog.

•  When all replacements are made, click OK to dismiss the confirmation message (you can leave the other dialogs onscreen if they are still open).

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

Step 5.

In this step, you need to change the item that Find and Replace will seek.

•  Position the cursor in the "Replace" field of the Find and Replace dialog.

•  Delete the [HRt] code (e.g., with Backspace) you just used, then insert a [HPg] code in its place.

[If the Codes dialog is not onscreen, click Match, Codes..., HPg, Insert on the Find and Replace dialog. The image in Step 2 above shows the HPg code located a few choices above the HRt code in the Codes dialog.]

See next image's
"Replace" field for the result.

Step 6.

•  Position the cursor in the "Replace with:" field, and use the Replace, Codes dialog to insert another [HRt] code at the end of the codes already there. [Alternatively, you could simply select the existing [HRt] code, copy it with Ctrl+C, then paste the copy with Ctrl+V.]

The Find and Replace fields should now look like this:

Find and Replace with EndField and 2 returns


Step 7.

You now need to separate all records with a [MRG:ENDRECORD] code.

•  Position the cursor between the two [HRt] codes in the "Replace with:" field. [If the Codes dialog is not open, click on Replace, Codes (and tick the box, "Display merge codes only" in the Codes dialog).]

•  Scroll down and select ENDRECORD in the Codes dialog, then click Insert, then Close.
[You can also just use Insert & Close instead of separately pressing Insert and Close.]

The
Find and Replace fields should now look like this:

Find and Replace with EndRecord code

[Expanded for clarity:] [MRG:ENDFIELD][HRt][MRG:ENDRECORD][HRt]

Step 8.

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:

Jane DoeENDFIELD
12 Ash Street
ENDFIELD
Anytown, OR 99999
ENDFIELD
ENDRECORD

John Doe
ENDFIELD
34 Oak StreetENDFIELD
Anytown, OR 99999
ENDFIELD
ENDRECORD

...etc.

In this example each record has 3 fields to merge into 3 corresponding fields on a merge form. 

Tips:

☼  You might want to carefully review the records to remove duplicates or correct data in the various fields.

☼  See Laura Acklen's tutorial about setting up a merge.

☼  You can convert the data file to a data table. See the section here.

Step 9.

Save this data file with a .DAT filename extension (e.g., MyLabels.dat).

The merge 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];

or

•  converted to a WordPerfect table
using the method below for easier maintenance (sorting, etc.) and merging;

or

•  converted to a .CSV file (using the method below) for exporting to other programs that can use that format.

Up arrowPage Top

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

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

Procedure

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

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

Step 2. Then -

•  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 for sorting/merging; merging data files into a table; and converting data files to "comma-separated-values" (.CSV) files

Note: Always make a backup of your file before following these methods.

Method A. Convert a merge data file (.DAT) to a WordPerfect table.


This is easier than Method B -- but Method B has various uses in complex documents.

A merge data file is one where each record ends with ENDRECORD and each field in the record ends with ENDFIELD.

Step 1. Open the merge data file (.DAT) and select the entire file with Edit, Select, All. (Note: A shortcut like Ctrl+A may not work here, so use the Edit, Select, All method.)

Step 2. Click on Table, Create (in WordPerfect 9 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. Here, choose "Merge Data File".

Step 3. Enable both "Equal Column Widths" and "Merge Data File". Click OK, then save the file.

You now should have a WordPerfect table with multiple rows (records) and columns (fields) -- which (1) can be sorted and/or (2) be used as the source data for a merge, if desired. (You might want to review the table and edit it for any incorrect data and formatting issues before using it in a merge.)

Method B. Merge a data file (.DAT) into a WordPerfect table.


Here's how to merge a traditional data file (.DAT), where each record ends with ENDRECORD and each field ends with ENDFIELD, into a normal WordPerfect table with multiple rows (records) and columns (fields).

[These steps were tested in WordPerfect X7, but should be similar back to at least WPWin6.1.]

Step 1. Create a merge form with Tools, Merge. Click the Form Document button and choose Create Form Document. This opens the Associate Form and Data dialog. Choose the "Associate a data file" button, and then choose the data file (.DAT) from the adjacent browse field and click Select.

Click OK to close the
Associate Form and Data dialog.

Click Cancel to close the Merge dialog. The Merge bar (Insert Field..Options) should still be visible above the document's text area.

[Tip: If there are lots of fields in a record you may want to set the form 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. (You can always Zoom in to the small text with View, Zoom.)]

Step 2. Create a two-row table in the merge form with Table, Create (in WordPerfect 9 and earlier, use Insert, Table). Specify as many columns as there are fields in a record in your data file.

Step 3.  Type headings into each cell in the first row. These help identify your merged data (see below for an example). Note: The first row is optional but it helps identify the type of data in each column in the merge data file and the merged output.

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 last cell in the second row (after all codes), click Insert Merge Code on the Merge Toolbar, and choose "More...". Find REPEATROW in the Codes list and click Insert, then Close.

Click Close on the Insert Field Name or Number dialog.

You should see something like this (assuming you are using something like the example 3-line address labels in the section above):

NAME
ADDRESS
CITY-ST-ZIP
FIELD(1)
FIELD(2)
FIELD(3)REPEATROW

Important: Before leaving these table-creation steps (#2 and #3): With the cursor in the table, use Table, Format (or just right-click the table). On the Table tab in the Properties dialog, be sure that "Insert new rows automatically" is enabled. Click OK to close that dialog.

Tip: See
also the merge commands NEXTRECORD, PAGEOFF/PAGEON, ONERROR and other merge and/or macro commands that may be revelant. Footnote 2 gives an example of these commands.

Step 4. Merge the file as you would any other form file: Click Merge on the merge bar to open the Merge dialog, output to a New Document, etc. Then click the Merge button at the bottom of the Merge dialog.

The new document will have a table where the first row contains the headings and the remaining rows contain the merged data, one record per row.

You now should have a WordPerfect table with multiple rows (records) and columns (fields) -- which (1) can be sorted and/or (2) be used as the source data for a merge, if desired. (You might want to review the table and edit it for any incorrect data and formatting issues before using it in a merge.)

Method C. Convert a merge data file (.DAT) to a Comma-Separated-Values (.CSV) file.


Here's how to convert a simple merge data text file (.DAT) to a comma-separated file (.CSV) [a.k.a. a comma-delimited file], 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 other program that can read such data) should recognize.

Note that any address lines in your data file that contain commas will confuse this method, so there should be deleted first. [The U.S. Post Office prefers eliminating commas and periods from mailing addresses, so this should not be a problem.] *

Back up the file first. Go to the top of the document. Open Find and Replace.

Step 1.
Find all commas (,) and replace with a space character (press Spacebar in the Replace with field).

Step 2.
Find [HPg] codes and replace with a [HRt].

Step 3. Find [ENDFIELD][HRt] pairs and replace with a comma (,). 
Note that the Codes dialog you used has a small checkbox to "Display merge codes only". Enable that box to search for just merge codes.

Step 4. Find comma+ENDRECORD pairs -- ,[ENDRECORD] -- and replace with <Nothing>.


The file will now be a "comma separated values" file.

Be sure to save it with a .CSV filename extension before exporting it.

---
* Generally, if a comma is required in a field it can be added back (in the final .CSV file) in that field if the entire field is enclosed in double quote marks. For example: "San Francisco, CA". Most programs that can use a .CSV file will then see the entire field as a single (literal) string of characters rather than two fields separated by a comma. [Similarly, fields with existing quote marks should be enclosed in double quotes.]
For more on .CSV format and its requirements see (e.g.) https://en.wikipedia.org/wiki/Comma-separated_values

Extract table cell data that is not in merge format so it can be used as a merge data file

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, containing 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

etc.

The problem here -- insofar as a WordPerfect merge is concerned -- is that the table cells contain data that is separated into one-line "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 end with ENDFIELD merge codes, and where each record ends with an ENDRECORD merge code.

Therefore, you have to extract the data from the table and convert it to a merge data file, so that it looks like this:

John SmithENDFIELD
123 Main Street
ENDFIELD
Portland OR 97229ENDFIELD
ENDRECORD

Mary Jones
ENDFIELD
456 South AveENDFIELD
Seattle WA 98110ENDFIELD
ENDRECORD

Bob Black
ENDFIELD
678 Western BlvdENDFIELD
San Francisco CA 96200ENDFIELD
ENDRECORD

etc.

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.

Procedure

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 the data fields with tabs ([Left Tab] codes).

•  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 in one continuous 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 in Reveal Codes, 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 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.

[Tip: A merge data file can be converted to a table for easy maintenance, sorting, merging, etc. See the section here.]

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.

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

CODES(
CHAR(rooms;Enter the number of rooms (1 or 2); Number of Rooms)
IF(VARIABLE(rooms)=1)
DOCUMENT(c:\mrgfiles\oneroom.mrg)
ELSE
DOCUMENT(c:\mrgfiles\tworooms.mrg)
ENDIF
)
..."

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):
PAGEOFF ONCANCEL(Quit)
ONERROR(GO(done))
Case Number
File No. Note
Comments
LABEL(newrow)
[CountDisp][CountInc] Field(Case) Field(File) Field(Note) Field(Comments)
NEXTRECORD
GO(newrow)
LABEL(done) PAGEON

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.

Advantages:

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


Tips

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

    TableCalculateAll  
    Return
  • 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.)


[Also, 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."]

The method below was 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 (corresponding to the number of columns in the paper label stock) -- 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.]

Instructions

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:
vCols:=3
//
If(?NumberOpenDocuments>8)
    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!)
    Quit
EndIf
If(?DocBlank)
    MessageBox(;"Current Document is Blank";
    "This macro requires text that can be processed.";IconStop!)
    Quit
EndIf
// Convert the labels to a WP table:
// Store the current document's number:
vCurrentDoc:=?DocNumber
// Store the number of pages (labels):
PosDocBottom
vTotalPages:=?Page
PosDocVeryTop
// Open a new document:
FileNew
///CenterPages(Off!)
// Store the new document's number:
vNewDoc:=?DocNumber
// Create the table:
vTotalRows:=vTotalPages/vCols  // (number of rows needed)
vFrac:=FractionalPart(vTotalRows)
If(vFrac>0)
    vTotalRows:=(vTotalRows+1)-vFrac
Endif
TableCreate(vCols;vTotalRows)
///QuickmarkSet  // ("mark" the current cell)
PosTableEnd
vLastCell:=?Cell
PosTableBegin
ForNext(vIndex; 1; vTotalPages; 1)
    // Go back to the original document:
    SwitchDoc(vCurrentDoc)
    // Copy the entire label's text:
    PosPageTop
    SelectMode(On!)
    PosPageBottom
    PosLineVeryEnd
    If(StrLen(?SelectedText)=0)  // (prevents an error)
        SelectOff
        Type(" ")  // i.e., one space character
        SelectCharPrevious
    Endif
    EditCopy  // Copy selection to clipboard
    SelectOff
    PosPageNext
    // Go to the table document:
    SwitchDoc(vNewDoc)
    // Paste the label's text into the table cell:
    EditPasteSimple
    vCurrentCell:=?Cell
    PosCellNext
EndFor
Return
// 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):
PAGEOFF ONCANCEL(Quit)
ONERROR(GO(
done))
CHAINMACRO(numbering)
Item#
Case Number File Number Note
Comments
LABEL(newrow)

Field(Case) Field(File) Field(Note) Field(Comments)
NEXTRECORD
GO(newrow)
LABEL(done) PAGEON

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.

Notes

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")).

Alternative:
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):
vInsertSuffix:=1
// Store the desired suffix (N.B.: periods/fullstops don't work):
vSuffixChar:=":"
//
// 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)
PosTableBegin
// Then, get the total number of rows (minus 1):
PosTableColumnBottom
vRows:=?Row-1
// Set the starting number value -
vStart:=1
//
// 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)
    PosLineEnd
    Type(vSuffixChar)
    Return  // (or use Quit)
Endif
PosTableCellDown
Type(vStart+1)  // (type the second number)
// Go back to first numbered cell -
PosTableCellUp
// Populate the cells -
PosTableCellTop  // (i.e., beginning of cell)
// Select the rest of the column -
SelectOn (CharMode!)
RepeatValue (vRows)
PosTableCellDown
// Fill the column with incrementing numbers -
TableDataFill  // (same as "QuickFill" command)
SelectOff
// Optional: Go to table top left cell -
PosTableBegin
// Optional: Add a suffix to numbers, such as
// colons or other punctuation specified above -
If(vInsertSuffix=1)
    PosTableCellDown  // (go to row #2)
    PosLineEnd
    Type(vSuffixChar)
    ForNext(i; 1; vRows-1; 1)
        PosTableCellDown
        PosLineEnd
        Type(vSuffixChar)
    Endfor
    PosTableBegin  // (Optional: Go to table top)
Endif
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/WPX7 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

[Note: To use a spreadsheet as the data file (i.e., the data source), see
Doug Loudenback's online manual entitled "USING WORDPERFECT'S MERGE TO CREATE MAILING LABELS FROM A QUATTRO PRO (or Excel) SPREADSHEET FILE," here. Merging to a table is similar. (The entire manual, with graphics and in PDF format, can be downloaded here.)]

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 [to contain the data from the data file; see also the Tips below]
• Rows — 2

5. Click Create, and type a heading in each cell of the first row (e.g., First Name, Last Name, Street Address, etc.).

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.

- - -
Notes


- After merging, the table expands one row for each record in the associated data file.
- Press Tab to move to the next cell.

Tips

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

- [From a post by Larry Lewis on WordPerfect Universe here:]  If you want the table cells in each row to contain individual records rather than individual fields in a single record (i.e., one record per row), place all the
FIELD() merge codes for a record in the first cell in the row, then duplicate that cell for the remaining cells in the row (no need for headings in this case).Then add NEXTRECORD at the bottom of each cell in that row except for the last cell, which should contain REPEATROW, something like this (assuming a 4-column table, which should produce a table with 4 records per row):
FIELD(1)
FIELD(2)
FIELD(3)
NEXTRECORD
FIELD(1)
FIELD(2)
FIELD(3)
NEXTRECORD
FIELD(1)
FIELD(2)
FIELD(3)
NEXTRECORD
FIELD(1)
FIELD(2)
FIELD(3)
REPEATROW



Footnote 4

[Continued from above...]

From Gordon McComb (here):

"... When preparing [separate] sub documents for merging or inserting, people will often "format" them for better appearance as a stand-alone document. This includes putting a font code, tab set, header or footer, or other formatting at the start of the document body. That code will often be an open (unpaired) code, but that doesn't really matter, as when the document is imported into the output, WPWin will convert most of these to paired code (there are some exceptions, like tab sets, headers and footers, and so on).

When this document is subsequently merged in, these codes go with the text. [Italics added.] This is not always (and is often not) desirable. You get font and other formatting changes when you don't want them, headers and footers that "mysteriously" change, and if you need to update the look of the document, you have to go through all the subdocuments as well. It's always better to leave formatting out of the documents if you don't specifically want that formatting to be included in the out[put]. Or, if you must apply formatting to better visualize the document, put the codes in [the initial] DocumentStyles [code], where they will not be inserted during a merge or import. ..." [Ed.: You can just double-click on the Open Style: DocumentStyle code at the top of the document to add formatting there that applies to the entire document. Search the Toolbox site for examples of "hide the code".]