title: Word VBA macro to insert file and merge formatting
body: <p>I have a template with a header/footer and text formatting. I would like to write a macro to fill this template with the contents of an .rtf or .doc file. Also, I would like to merge the formatting so that I keep the header and formatting from the template file, and the pictures in the .rtf or .doc files.</p>
  
  <p>Cut-and-paste works great. If I open and save the template file, open the file to insert, select all, and paste special with "merge formatting", then I get exactly what I want. I just want a more scalable solution.</p>
  
  <p>I wrote a macro that does most of this, but it fails to merge the formatting and drops (or hides) the header and footer. I thought the correct approach would use the <a href="http://msdn.microsoft.com/en-us/library/office/aa212280%28v=office.11%29.aspx" rel="nofollow noreferrer" title="InsertFile">InsertFile</a> method, but I can't figure it out.</p>
  
  <p>Any pointers would be appreciated (I'm new to both Word and VBA).</p>
  
  <pre><code>Sub InsertFile()
  
      currentPath = ActiveDocument.Path
  
      Set FileBox = Application.FileDialog(msoFileDialogFilePicker)
  
      With FileBox
          .Title = "Select the File that you want to insert"
          .InitialFileName = currentPath &amp; "\" &amp; "*.rtf"
          .AllowMultiSelect = False
          If .Show = -1 Then
              FiletoInsert = .SelectedItems(1)
          End If
      End With
  
      Selection.Range.InsertFile FiletoInsert
      Set FileBox = Nothing
  End Sub
  </code></pre>
  
  <hr>
  
  <p>Update - I also tried <a href="https://superuser.com/a/444799/45020">this approach</a>, which seems to use cut-and-paste, but the results are the same.</p>