none
Insert File to Word Document with current format RRS feed

  • Question

  • Hi,

    I want to add multiple Word documents into one document by using Microsoft.Office.Interop.Word. 

    First, I open the a document (cover page), and then insert other document

    Here is my code:

    doc = wordApp.Documents.Open(
                                                            ref objFileName,    //FileName
                                                            ref objMissing,   //ConfirmVersions
                                                            ref objMissing,   //ReadOnly
                                                            ref objMissing,   //AddToRecentFiles
                                                            ref objMissing,   //PasswordDocument
                                                            ref objMissing,   //PasswordTemplate
                                                            ref objMissing,   //Revert
                                                            ref objMissing,   //WritePasswordDocument
                                                            ref objMissing,   //WritePasswordTemplate
                                                            ref objMissing,   //Format
                                                            ref objMissing,   //Enconding
                                                            ref objMissing,   //Visible
                                                            ref objMissing,   //OpenAndRepair
                                                            ref objMissing,   //DocumentDirection
                                                            ref objMissing,   //NoEncodingDialog
                                                            ref objMissing    //XMLTransform
                                                            );

    Word.Selection selection = wordApp.Selection;

    selection.InsertFile(strFile, ref objMissing, ref objConfirmConversions, ref objMissing, ref objMissing);

    It can insert all documents to one document but the cover page (the first one) is shown at the end of the document.

    When I use another method to insert documents, it works properly. The cover page can appear at the beginning of the document

    Here is code of method 2:

    doc = wordApp.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing);

    Word.Selection selection = wordApp.Selection;

    selection.InsertFile(strFile, ref objMissing, ref objConfirmConversions, ref objMissing, ref objMissing);

    The format (e.g. margin) of generated document is not the same as my original documents.

    How Can I create a new document and insert all documents to it and keep the original format?

    Can I keep the original document layout (e.g landscape) when inserting it to a portrait document?

    Tony

    Thursday, March 27, 2014 11:54 AM

Answers

All replies