Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Combining Documents.

Combining Documents

Written by Allen Wyatt (last updated June 26, 2018)
This tip applies to Word 97, 2000, 2002, and 2003


Stuart wrote about a need he had of consolidating many different text files into a single Word document. Using the Insert | File option proved to be tedious, particularly when there were 20 or 30 different text files to be combined.

Fortunately for Stuart, his file names were predictable: C1000.TXT, C1001.TXT, etc. This makes putting together a macro to do the consolidation rather easy. The following example will look for files C1000.TXT through C1030.TXT, all in the C:\ directory, and combine them into the current document:

Sub CombineFiles()
    Dim J As Integer
    Dim sFile As String
    For J = 1000 To 1030
        sFile = "c:\c" & Trim(Str(J)) & ".txt"
        If (Dir(sFile) > "") Then
            Selection.InsertFile FileName:=sFile, ConfirmConversions:=False
            Selection.TypeParagraph
        End If
    Next
End Sub

If you want to change the range of files being inserted, just change the values at the beginning of the For ... Next loop. If the files are in a different directory, you can change the path used in the next code line, where sFile is set. If a file within the range is missing, it is automatically skipped.

There is an even easier way of combining files, however, that doesn't even involve the use of Word. You can use the following command at the DOS command line:

copy C1???.txt single.txt

This would combine up to 1000 files, C1000.TXT through C1999.TXT, into a single text file called SINGLE.TXT. The original files remain untouched. If you wanted to combine a smaller number of files, you could use this format:

copy C1020.txt+C1021.txt+C1022.txt+C1023.txt single.txt

This usage results in the four files, C1020.TXT through C1023.TXT, being combined into SINGLE.TXT. You can add as many files together in this manner as you desire.

There is one caveat to this technique, however. The copy command results in no extra characters being added to a file at all. In other words, the contents of C1021.TXT are placed immediately after C1020.TXT. For example if C1020.TXT contains "text 1020" and C1021.TXT contains "text 1021" then SINGLE.TXT will contain "text 1020text 1021". The only way around this to either edit each source file to make sure it ends with a carriage return, or to use the macro previously presented.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1607) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Combining Documents.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Deleting Commented Text

Word allows you to add comments to your document to aid in the development of the document. At some point you may want to ...

Discover More

Using Strikethrough Formatting

Need a line through the middle of your text? Use strikethrough formatting, which is easy to apply using the Format Cells ...

Discover More

Understanding Auto-Population of Cells

Auto-population of your formulas can be a useful tool when you are adding data to your worksheets. It would be even more ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (menu)

Embedding TrueType Fonts by Default

If you use TrueType fonts frequently, you might want to set Word to embed those fonts by default. Here's how to do it.

Discover More

Saving in MS-DOS Text Mode

Over the years Microsoft has made changes in Word. One change is to the import and export filters provided with the ...

Discover More

Making Backup Copies

When you save your documents, Word doesn't normally make backups of your files. If you want the program to do that, it ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 7?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.