question

EugeneLerner-3404 avatar image
0 Votes"
EugeneLerner-3404 asked

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


office-vsto-com-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers