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-2018 by Barry MacDonnell. All Rights Reserved.

Page updated Jan 23, 2018

MAKESUBS - Make subdocuments from multiple files

Download MAKESUBS.ZIP (v1.09; 11/16/2012; 22,017 bytes)

Compatible with WordPerfect 9 and later versions

WordPerfect 11 users: See important information about using macros in the first release of WP11 ( at the top of this page.

Downloading, Documentation, Modifications, and Support

Some resources  -

For more information on creating master and subdocuments, see -

•  WordPerfect's online Help (F1 key, "Using master documents")

Laura Acklen's Corel tutorial, "Working with Master Documents and Subdocuments".
•  "Notes and tips for Master documents and Subdocuments"
(in the next column -->

•  Formatting subdocuments can be more easily and reliably controlled with styles -- especially custom styles.

•  Problems? Need more help? Search (or join) WordPerfect Universe forums for peer-to-peer help with WordPerfect Office.

MakeSubDocs.wcm is a WordPerfect 9 (and later version) macro that inserts multiple files -- e.g., book chapters -- into the current (master) document as linked subdocuments.

When you play the macro, a menu (screen shot) appears with several options.

[See Notes and Tips below for more information on using the Master/Subdocument feature.]

Before using MakeSubDocs.wcm for the first time...

Gather the files ("subdocuments") you want to include in the Master document in the same place.


Be sure to keep the Master document in a separate folder from all the subdocuments. Reason:
MakeSubsDoc.wcm will process ALL files found in that folder that have the specified filename extension (.WPD is the default extension). The master will most likely also have the same extension, so you'll want to keep it separate from the other files.

Related tips:

It's also a good idea to copy all the files you want to include as subdocuments into that separate folder before playing this macro. Copying the files, rather than moving them, will help ensure that you have a backed up version of them.

If you have an existing document you want to use as the source of the subdocuments it can be split up by saving sections of it as separately named files (perhaps with similar names like Chapter 01, Chapter 02, etc.). You can do this manually or with the help of a macro: See the notes and tips section below.

 See how it works.

You may want to play this macro while inside a new, empty master document (see notes and tips below) and with a few sample subdocuments until you see how it works.

The order of appearance of subdocuments in the Master document.

The alphabetical order of appearance of the subdocuments in the resulting master document may be different than you expected due to the way (some versions of) Windows physically stores files in its folders. Hence, you have a choice of "ascending" or "descending" order on the macro's menu (screen shot). Ascending alphabetical order is the default and works for the majority of users. Try each choice to see which works best for your particular setup.


You may want to modify the default values displayed on the macro's menu. You can change them in the redlined User Modification Area of the macro's code. (Use Tools, Macro, Edit to modify the macro's code.)


The first time you play the macro or edit it, you might get a pop up warning message about the SortArray command being obsolete.

However, this command seems to work just fine (and is used in other macros in the Library and by other WordPerfect macro experts).

Just press "Continue Compilation" if you get this warning.

Explanation: The appearance of messages about obsolete macro commands depends on the version of WordPerfect, and in any case they appear only the first time you play the macro (or when the macro is edited/saved.) These warnings were implemented by Corel in WP9/sp4 and were removed in a subsequent version. But even though many commands have been named 'obsolete' by Corel since very early versions — probably with a view toward consistency and conservation of code overhead — most still work, and probably will work in versions to come. (If you want more technical information about FileFind, SortArray, etc., see the comment at the end of the macro.)

Be sure to review the Notes and tips in the next section below.

Notes and tips for Master documents and Subdocuments

[If you intend to use the MakeSubDocs macro to help you create a functioning master document be sure to see the section above. Even if you don't use it, the following tips about using the WordPerfect master/subdocument feature might be helpful to you.]

☼  Overview

•  A master document is a regular WordPerfect document -- created as a sort of "shell" or "container" with embedded links (seen in Reveal Codes as individual [Subdoc] codes) to specified external files on your disk (the subdocuments). (See the next tip on how to create the master document.)

•  When you expand the master (with File, Document, Expand master) WordPerfect displays the linked subdocuments in the master, producing one large file. The subdocuments are still on disk as separate files. This linking behavior is a common source of confusion about where each subdocument's content actually exists.


- In an expanded master document you can search through it, make global format changes to it, etc., just as you can with any open document.

- Be sure to read the tips below on removing links from an expanded master document. For example, if you remove all of them (easily done with Find and Replace) the result will be a single document -- as though you had used Insert, File to join ("concatenate") all the (subdocument) files on disk into the open (master) document.

•  When you condense and save the master document (with File, Document, Condense master) it will shrink back to displaying just the linking codes (plus any separate material that you have added to the master itself).

•  You can also expand some subdocuments and condense and/or save others, so that you can work on just certain sections of your project more easily.

•  See the rest of the points below -- especially about working simultaneously on a master document and one or more subdocuments.

☼  To create a master document (basic steps)

Decide on the type of document to use as the master document

You could use any regular WordPerfect document as a starting point for the master document, but it probably is best to start with a new blank document and then set up any introductory material in that master document.

Use a separate folder for the subdocuments

For the purpose of using the MakeSubsDocs.wcm macro, you should place the files that you wish to use as subdocuments in their own folder, separate from other files and separate from the master document file. (As well, it's always a good idea to archive the originals in another location, just in case.)

Even if you create the master document without the help of MakeSubDocs, it still is a good idea to keep all subdocuments together.

Want to use material in an existing document for your subdocuments?

If you have an existing document that you wish to break up and use the parts as subdocuments you can select portions of the document and use the Save (or Save As) buttons to create separate subdocuments. [Tip: The Splitter macro might help here since it can break up a file more or less automatically.]

Linking the subdocuments to the master document

You can link the subdocuments to the master document from inside the master either with -

[A] File, Document, Subdocument (to individually choose the files to include);

or with the -

[B] MakeSubDocs macro (to quickly include all files found in the separate subdocument folder).

☼  Get a little practice

Although it's not "rocket science" there's a little bit of "beyond-newbie-user" information to learn here.

Start simple

It might even be a good idea to create a new, fairly simple master document with 2 or 3 sample subdocuments linked to it, and then play with them a bit to see how things work -- especially with some formatting issues, such as those discussed below.

Backups, backups!

Until you are comfortably familiar with the master and subdocument feature ...

•  Make backups of the master document to another folder or drive.
Note especially that your master document contains full drive-and-path links to its subdocuments, so be careful not to accidentally open a back up copy of that master to use it -- or it might overwrite the original same-named subdocument files (to which it probably is still linked). In other words use backups to restore, not to use.

[Renaming backup files to identify them in a consistent manner as archived backups is a good idea; they can always be renamed to their original names if they need to be moved into their original location to replace the "bad" file there.]

•  Make multiple interim backups of subdocuments to another folder or drive (and in a different location from your master document backups). These are the most important parts of your master document. You could use a separate third-party program that can automatically make multiple backup versions of each changed file. See here for a few suggestions.

If you restore any of these backed up subdocuments be sure they are in the same path and have the same name as the originals to allow the [Subdoc] links in the master to work properly.

To see a [Subdoc] link's current path and filename: In the master, just place your cursor to the left side of a [Subdoc] code in Reveal Codes to view the currently designated path and name of the subdocument on the code itself. (If you delete the code you can re-link the master at that point to its subdocument with File, Document, Subdocument.)


Develop a habit to CONDENSE the master BEFORE saving or closing it.  Otherwise (and in addition to an issue of using unnecessary disk space) if your expanded master document might be saved later it could overwrite any previously (and separately) edited subdocuments that are linked to it. See the Corel Tutorial (next) for more on why to use this procedure.

[Thanks to Larry Lewis for several of these tips.]

☼  Read the Corel Tutorial

The Corel tutorial, "Working with Master Documents and Subdocuments" (which originally appeared in the March 2005 edition of the old Corel Newsletter), contains some valuable tips such as these relating to saving the master and subdocuments:

"... You should always condense a master document before you [close it or] save it. Otherwise, you save the same information twice [in the expanded master and in the subdocuments] and consume twice the disk space. Because you've already saved the subdocuments [with the Condense/Save Subdocuments dialog], you don't need to save that same information in the master document.

If you are working in both master documents and subdocuments [i.e., the master and one or more subdocuments are open simultaneously in separate windows], you may run into a situation whereby changes that you have made to a subdocument and saved do not show up in the expanded master document. These changes will appear in the master document only if you follow this procedure:

1. Condense and save the master document.
2. Make changes to the subdocument.
3. Save and close the subdocument.
4. Open and expand the master document. [That is, refresh the SubDoc links.]

The changes now appear in the expanded master document. At this point, you should generate the document (Tools, Reference, Generate) to update [any] index, table of contents, table of authorities, and so forth. ..." [Emphasis and annotations added.]

☼  Condense subdocuments without saving them?


Be especially aware that when condensing one or more subdocuments without saving them you merely hide them from view and any changes previously made to the subdocuments will not be saved at that time.

[Note: If you use File, Document, Condense Master, it brings up the Condense/Save Subdocuments dialog; this dialog is where you can choose the Subdocuments to condense and/or save by ticking or clearing their adjacent check boxes. The dialog's default setting is to condense and save all subdocuments.]

This is analagous to using an outline, where you can hide/expand various outline levels to help you focus on particular sections of the document. But it differs from an outline in that if you don't save subdocuments (in the Condense/Save Subdocuments dialog), the edits to the subdocuments are lost -- even if you save the master document.

While this might be what you want to do, you should know that changes in the subdocuments must be deliberately saved [i.e., check boxes ticked in the Condense/Save Subdocuments dialog] if you want to retain any changes -- just like any other open documents.

☼  Master document formatting codes will apply to subdocuments, except where codes of the same formatting type but with different settings are found in a subdocument

In WordPerfect, format codes take effect until replaced or discontinued. This is known as stream formatting (for more see here).

Since subdocument codes are "downstream" from the expanded master document, they can replace earlier versions with different settings (such as if they have a different line spacing from the line spacing code in the master). Conversely, "upstream" codes can affect material in later subdocuments, as explained below.

, format codes can be stored inside styles (for more information see the Styles and Custom Styles pages) so be sure to check styles if they are "upstream" from a format problem (including the initial [Open Style: DocumentStyle] style code in documents). You can double-click on a [Style] code in Reveal Codes to examine the Contents pane.

Keep this "stream" model in mind when trying to solve format issues in documents. Also see the tip by Charles Rossiter below about forcing subdocument formatting to "stick."

☼  Codes missing?

If the same formatting code with the same settings exists in both the master and the subdocuments, it might be stripped out in subdocuments (WordPerfect will see it as redundant) when you condense and save the master: See Footnote 1. [Also see the next item about styles.]

☼  Master document styles will override any subdocument styles that have the same name (for more information on styles see the Styles and CustomStyles pages)

This includes the initial Open Style: DocumentStyle code that is found at the beginning of all documents. As Noal Mellott wrote on WordPerfect Universe:

"The codes in the master document's OpenStyle will override and overwrite all the [initial] OpenStyle [code]s in the subdocuments when the file is generated...."

Note that WordPerfect styles are like small containers, and a [Style] code can contain other styles as well as format codes, etc., so you should open them (double-click on the code) to see what they might contain when setting up or formatting a master document with subdocuments.

Thus, same-named styles can create problems -- but see the tip below for a solution.

For example, some formatting in the subdocuments can be replaced by similar formatting located in the master document's style(s), which is "upstream" from them.

Also, the entire contents of a "downstream" style's code can be replaced by the contents of a same-name style in the master, and will be saved with the subdocuments.

(Conversely, new styles with unique names created in subdocuments -- such as you might create with the following tip -- are saved with the master document. This can be handy if you add more subdocuments later and need to apply the unique style: they will be available to subdocuments because they will be "inherited" from the expanded master document.)

Tip: You can force subdocument formatting to "stick":

[From Charles Rossiter, Corel C_Tech:]

"[1.] At the top of a sub-document, set up your formatting as you wish. Now select all the codes (and text, if any) that make up that formatting, and do Ctrl+C to copy to the Windows clipboard.

[2.] Next, do Format, Styles, Create. Name the style [12 characters maximum].

[Ed. note:

Use a unique name for each such custom open style for your subdocuments.

For example, you could use _InitChapt for the chapters, _InitAppend for the appended materials, etc..

The Type of style should be set to "Document (open)" so it applies to the entire subdocument.

Note that by naming the style with a leading "_" the style will be at the top of the Select Styles drop-down list on the text property bar, making it easy and quick to select.]

[3.] Click in the style editor window [i.e., its Contents pane] and do Ctrl+V to [paste] your chosen formatting.

[4.] Save the style.

[Ed. note:

For more on creating and saving custom styles, including saving them to your default template or other template, see here.]

[5.] Then whenever you first [or next] open one of your [sub]documents, apply that [custom] style [at the top of that document].

[Ed. note:

Don't put the new custom style inside the initial [Open Style: DocumentStyle] code in the subdocument, for the reason given above. Just put it in the body text area, before all other codes if possible. This should also make them easier to find and modify if necessary.]

If you find you need to change that [custom] style, you can just edit it and it will automatically apply to all documents with that style."

☼  Certain subdocument styles can override master document styles -- the opposite of the previous item

For example, if you used an outline style in one or more subdocuments, and you expect the outline to increment continuously throughout the entire (expanded) document (and not start at "1" in each subdocument), the [Outline] code that is inserted at the beginning of each outline can override the normal (sequential) order of outline items. Each [Outline] code contains a "definition" -- including numbering, where to begin, etc.

Solution: Expand the master document and find the first [Outline] code. Then delete all [Outline] codes after that one, in each of the included subdocuments that follow this first code. By deleting all but the first [Outline] code, the outline should be continuous through the master document.

☼  Reference tools (Table of Contents, Table of Authorities, List, Index, Cross References)

As Laura Acklen says in The Complete Reference Guide [a book that's apparently no longer available],

"...You can mark text for [automatic inclusion in] a table of contents, table of authorities, list, index, or cross-reference in both the master document and subdocument.
...If you're marking headings for a table, list, or index, you should consider creating a style for your headings with all the formatting and mark text codes [see here for how to do it for a table of contents or list].
Because expanding the master document compiles a list of all the marked [cross-reference] targets you might find it easier to mark targets in the expanded master document."


You can have multiple Tables of Contents (see the TOC page for how to create a Table of Contents) using the Master/Subdocument feature. Some documents require a separate TOC for appendices, chapters, etc. This is most easily done by placing individual TOCs in the desired subdocuments and generating them there. The expanded Master can then have a complete TOC referencing all subdocuments, if desired.

☼  Footnotes and endnotes

Laura also says (same reference as above):

"Don't place footnore or endnote option codes in the subdocuments. These codes, which control spacing between footnotes, separator lines, and whether numbering should restart on each page, should only be placed in the master document.
In most cases, footnotes should be numbered sequentially throughout a document. However, if you decide to restart the numbering in each subdocument, you need to place a footnote number set code in an open style at the top of each document [see Charles Rossiter's tip on open styles above]."

☼  Endnote placement

You can place endnotes at the end of the entire document by placing the placement code (using the Insert, Header/Footer dialog) at the end of the master. Or you can place them at the end of each subdocument (be sure to select "...restart numbering").

For the former, insert an endnote placement code at the end of the master document and choose Insert Endnotes at insertion Point from the Endnote Placement dialog.

For the latter, insert the code at the end of the subdocument(s) and choose Insert Endnotes at insertion Point and Restart Numbering.

For these and other reasons listed elsewhere here, you might consider setting up two custom templates for each type of project, one for a master document and one for a subdocument. Then you can insert existing material into a new document created with ("spawned by") either template and have your various styles and other format codes already present.

☼  Removing links

Two scenarios:

[A] When you remove a subdocument link (shown in Reveal Codes as [Subdoc]) from a condensed master document, the subdocument file remains on disk as a separate file. You have simply broken the link to it from the master document.

[B] When you remove a subdocument link
(shown in Reveal Codes as [Subdoc]) from an expanded master document, the subdocument file reverts to normal WordPerfect text inside the master document -- just as though you had inserted the file into the master document with Insert, File. It will no longer be a link to the external (subdocument) file. Remember to save the file under a different name if you wish to preserve the original master/subdocument linked format.

Related tip (for scenario [B]):

To quickly remove all subdocument links simply place the cursor at the very top of the expanded master document and then -
•  Click Edit, Find and Replace. Place the cursor in the Find field, and click Match, Codes.
•  Scroll down in the Codes dialog to "Subdoc Begin" and select it, then click Insert & Close.
•  Click Replace All.

Since the "Subdoc Begin" code is part of an On/Off code pair, removing the first part of the pair also removes the second part.

The document should now be an ordinary WordPerfect document, not a Master document. You might need to do some reformatting of the newly included sections.

Remember to save the file under a different name if you wish to preserve the original master/subdocument linked format.

Related tips (to the one just above):

- For simply joining files: Some users have made use of this "remove-the-links" trick on a new, MakeSubs-created master document to concatenate (join) hundreds of WordPerfect disk files into a single file, rather than tediously using Insert, File on each one.

- For converting multiple WordPerfect files to a Microsoft Word document: A user reported that this technique of turning all WordPerfect subdocuments into ordinary parts of the current document is a good method to use before converting it into a single Microsoft Word document.

☼  Use View, Draft (on the main menu) in the master document to see the names and paths of the subdocuments

If you don't see the path and name, click Tools, Settings, Display, Document and enable "Margin Icons."

Related tip: Place all subdocuments in a folder whereby the path to that folder and any subdocument name will not exceed 55 characters. Otherwise, you may not see the filename.

☼  You can rearrange subdocuments in a master document

Cut and paste: In a condensed master document, select the desired [Subdoc] code in Reveal Codes, cut it to the clipboard with <Ctrl+X>, and insert it in the new location with <Ctrl+V>.


If the master document is not condensed, select everything (for that subdocument) from the [Subdoc Begin] code to the [Subdoc End] code, including both of these codes, and cut/paste the material to the new location in the master document. This effectively moves the document's display in the master.


Automate the process: While you can manually cut and paste individual [Subdoc] codes in a master document to relocate them, or manually insert new [Subdoc] codes later,
here's a tip from Larry Lewis on WordPerfect Universe (here) that can help rearrange your preferred order of subdocuments as they should appear in the master document.

This also helps you keep the actual files organized on disk in the same "proper" order of appearance as in the master. It also helps you to quickly re-establish the master's links to the subdocuments even if you move all subdocuments to a different folder (thereby breaking the master's original links to them).

Example: Assume you just want to rearrange some (or all) of the subdocuments in the master.

[1] [Optional if not already done:] Create the master document's subdocument links -- i.e., insert the [Subdoc] codes using the MakeSubs macro (as above) or by manually inserting them.

[2] Expand the master document (as above).

[3] Make note of which subdocuments you want to re-order.

[4] Condense the master (see also the sections above about condensing).

[5] Navigate to the subdocuments folder and rename the subdocument files on disk with a leading number (or other string) as part of their filenames so that all of them will be sorted by name into the preferred order (see "the order of appearance" above).

[6] Open the existing master, delete all [Subdoc] codes in the master -- they are just links, as noted above -- and re-insert them again with MakeSubs (step [1]).

☼  Starting new pages

If you insert a hard page break (Ctrl+Enter) between each subdocument code in the master -or- at the top of each subdocument, you can force each of the subdocuments to begin on a new page.

☼  Consider setting up two custom templates for each type of project

Set up one for a master document and one for a subdocument. For more on custom templates see here.

☼  Turn on a warning message

One handy setting that can help eliminate the problem of accidentally deleting codes, especially when working with master/subdocuments: In Tools, Settings, Environment, Prompts (tab), enable "Confirm deletion of codes...."

☼  Backups

Make lots of backups when working with master and subdocuments. The MULTISAV macro, NewFN#.wcm, in the Library can help.

☼  Can a macro determine the state of a Master document (i.e., expanded or condensed)?

See Footnote 2 below.

Footnote 1

From Using WordPerfect Office X3 by Laura Acklen and Read Gilgen (Que, 2006):

"Automatic Code Placement (the behind-the-scenes WordPerfect feature that positions certain codes for you) . . . can strip out redundant codes, resulting in a subdocument that can no longer stand on its own. For example, let's say you have a double-spaced master document. When you expand a subdocument with a double-spacing code in it, the Auto Line Formatter [a component of Code Placement] strips out that code, because it's redundant. When you save the subdocument, it is saved without the double-spacing code so it is saved as a single-spaced document. . . ."

So it appears that Charles Rossiter's tip (above) about creating a new, custom style for the top of all subdocuments is a practical solution that will force the formatting of those subdocuments, regardless of what happens in the master document. Your formatting should "stick." It's a simple method, too, and relies on the simple idea that if you set codes at the top of a document they will be available for the rest of that document (unless replaced or discontinued). Since styles are like "containers," they are easily inserted where needed, even if they contain many format codes (and even text).

Footnote 2

Can a macro determine the state of a Master document (i.e., expanded or condensed)?

There does not seem to be a direct way for a macro to determine the state -- i.e., whether it's a Master/Expanded document, a Master/Condensed document, or it's NOT a Master document.

However, [Subdoc] codes in the Master change depending on the state of the Master:

•  In a condensed Master document, you'll see single [Subdoc] codes for each subdocument linked to the Master. (The numeric value of the code is 2516.)

•  In an expanded Master document, you'll see paired codes: [Subdoc Begin] and [Subdoc End]. (Their numeric values are 3796 and 4052, respectively.)

Therefore, you could simply have a macro search for the existence of one or the other codes (either [Subdoc] or [Subdoc Begin]) to tell the macro which state the Master is in, condensed or expanded.

Here's a demonstration macro that should do the job. Modify the code to suit your needs.

BE SURE to insert the appropriate binary codes using the Codes button on the Macro toolbar, where indicated in the code below in the SearchString() commands. That is, remove the text placeholders in them (i.e., [Subdoc Begin] and [Subdoc]), but be sure to retain the double quote marks around the binary codes you insert to replace the placeholders.

// Determine the state of the current document -
// Master/Expanded, Master/Condensed, or not a Master:
[Subdoc Begin]") // (<= insert [Subdoc Begin] code)
   "Found a [Subdoc Begin] code: It's an expanded master document.")
[Subdoc]") // (<= insert [Subdoc] code)
   "Found a Subdoc code: It's a condensed master document.")
   "No Subdoc Begin or Subdoc codes found: It's not a master document.")