Click here to Skip to main content
15,077,428 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I have to insert text from the one word document (having header and footer) to the another word document(also having header and footer).

I just want to transfer text from one document to another document without changing header and footer.

What I have tried:

I have tried following code.

var application = new MSWord.Application();
var originalDocument = application.Documents.Open(@"C:\Word\Source.doc");

originalDocument.ActiveWindow.Selection.WholeStory();
var originalText = originalDocument.ActiveWindow.Selection;


Microsoft.Office.Interop.Word._Application oWord;
object oMissing = Type.Missing;
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = false;
oWord.Documents.Open(@"C:\Word\Destination.doc");
oWord.Selection.TypeText(originalText.Text);
oWord.ActiveDocument.Save();
oWord.Quit();

using this code Text is inserted from source document to destination doc. But it disturbs footer of destination document.
Posted
Comments
Dmitriy Gakh 2-Jun-16 3:35am
   
To insert one document into another without changing header/footer you need inserting section break in way you new text will be in new section.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900