Combine and Merge RTF Files Without Formatting Loss

This Visual Basic macro is intended to combine and merge multiple RTF files without losing the formatting. Basically it will create a new file, and inserts each RTF file as an object so it maintains the formatting of each file instead of inserting text from the files. This is basically what one would want if the RTF files are scanned results of an OCR system.

To use this macro do the following,

  1. Select Developer tab in the Word 2007 ribbon, and if the Developer tab is not available follow these instructions from Microsoft Office Website, before proceeding to the next step
  2. Click on Macros
  3. On the Macro name: text field in Macros Dialog Box, type in your macro name, e.g. MergeRtf
  4. Click Create
  5. Copy and paste the following on the blinking cursor position, just before End Sub line

    Documents.Add ' may delete this line if you want the rtf files to be added on the currently active file
    ChDir "C:\myFiles" ' change myFiles to the directory of the source rtf files
    myName = Dir("*.rtf") ' may change rtf to doc or txt
    While myName <> ""
    With Selection
    .InlineShapes.AddOLEObject, FileName:=myName, LinkToFile:=False, DisplayAsIcon:=False
    End With
    myName = Dir()

  6. Click on Save, or Press CTRL + S
  7. Click on Run Sub/Userform, or Press F5
  8. Depending on the amount of processing power of your CPU and the amount of file merged it will take several seconds to minutes, and you're done.
  9. Press ALT + Q to Close and Return to Microsoft Word

That's it. Enjoy.