VSTO - Appending one Word document to another fiasco
I explored two scenarios:
//Common steps:
Application wordApp = new Application( );
Document sourceDoc = wordApp.Documents.Open( "My main.doc" );
Document appendee = wordApp.Documents.Open( "My appendee.doc" );
Range sourceRange = sourceDoc.Content;
object end = sourceRange.End - 1;
Range newRange = sourceDoc.Range( ref end, ref end );
//Scenario 1: Attempt to paste at the range of the last character
newRange.FormattedText = appendee.Content.FormattedText;
//Problem: appendee text inserted at the first character "overlaying" two documents.
//Scenario 2: Attempt to insert a section
Section sec = newRange.Sections.Add( );
//Problem: System.Runtime.InteropServices.COMException: 'The specified range is not from the correct document or story.'
What am I doing wrong?
Please help.
Thank you,
Eugene