I am evaluating ASPOSE.Words as a possible solution for our company.
One of the goals is to merge two word documents and then save the result to another *.doc file.
The host document has VBA macros (Document A). We are simply writing the contents of Document B into the body of Document A.
This was easy enough.
However, resulting file after the save (Document C) no longer has the macros that Document A had…it appears that the macro’s did not survive the save.
Any ideas on what I may be doing wrong?
Here is the code:
//===============================================================
// Get the path to the *.Dot file and the KBrief WordML file.
// ===============================================================
object hostFilePath = Environment.CurrentDirectory + @"\kb.dot";
object contentFilePath = Environment.CurrentDirectory + @"\kb.xml";
// ===============================================================
// Open the two Documents
// ===============================================================
Document hostDocument = null;
Document contentDocument = null;
hostDocument = new Document((string)hostFilePath);
contentDocument = new Document((string)contentFilePath);
// ===============================================================
// Merge the wordML from the content *.doc file into the host *.doc file
// (Replacing all sections of the host document but keeping the macros).
// ===============================================================
hostDocument.Sections.Clear();
foreach(Section srcSection in contentDocument)
{
Node dstSection = hostDocument.ImportNode(srcSection, true, ImportFormatMode.UseDestinationStyles);
hostDocument.AppendChild(dstSection);
}
// ===============================================================
// Save merged result into a new File using date as unique file name:
// example: a_200809100113534751_new.doc
// ===============================================================
object newFile = Environment.CurrentDirectory + String.Format(@"\a_{0}_new.doc", DateTime.Now.ToString("yyyyMMddhhHmmssff"));
hostDocument.Save(newFile, SaveFormat.Doc);
MACROS ARE GONE in saved file…