0
votes

I need to create a same copy of existing word document and open it as another instance while the original first document being opened. The second word document do not save but user may have the option to save it or not.

This need to be done using OpenXML.

I will attached here the current implementation. This implementation is having several issues.

  1. The first document need to close first before use it in WordprocessingDocument using statement.

  2. The second newly created document need to save in local folder.

Code Initiation

 var doc = Globals.ThisAddIn.Application.ActiveDocument;
            doc.Save();
            string fileName = doc.FullName;
            doc.Close();
            using (WordprocessingDocument document = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document))
            {

}
1

1 Answers

0
votes

Why do you need to use OpenXML ? With Interop you could simply:

  • Open the existing document
  • Copy everything within the document range
  • Create a new document
  • Paste the other document in the new one

It's done quickly and does the job perfectly