none
Copy word document along with macros RRS feed

  • Question

  • Hi,

     using (WordprocessingDocument destDoc = WordprocessingDocument.Create("destination.docm", WordprocessingDocumentType.MacroEnabledDocument))

                {

                    WordprocessingDocument srcDoc = WordprocessingDocument.Open("macrosource.docm", false);

                    MainDocumentPart mainPart = destDoc.AddMainDocumentPart();

                    // Create the document structure and add some text.

                    // Get VBA parts from source document

                    VbaProjectPart vbaSrc = srcDoc.MainDocumentPart.VbaProjectPart;

                    VbaDataPart vbaDatSrc = vbaSrc.VbaDataPart;

                    // Create VBA parts in destination document

                    VbaProjectPart vbaProjectPart1 = mainPart.AddNewPart<VbaProjectPart>("rId9");

                    VbaDataPart vbaDataPart1 = vbaProjectPart1.AddNewPart<VbaDataPart>("rId1");

                    // Copy part contents

                    vbaProjectPart1.FeedData(vbaSrc.GetStream());

                    vbaDataPart1.FeedData(vbaDatSrc.GetStream());

    }

    The above code creates a new word document and copies the macros from the source document to the created document.But I need to copy the content too(along with macros,images,header,footer etc...the whole content) to the created document. How can I do this? Can any one share the C# code to this & guide me.TQ.

    • Moved by Jason Dot Wang Wednesday, September 12, 2012 5:59 AM This thread is about Word for Developers (From:Visual C# Language)
    • Moved by Cindy Meister MVPModerator Thursday, September 13, 2012 11:37 AM Open XML question (From:Word for Developers)
    Monday, September 10, 2012 5:51 AM

Answers

All replies