We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Macros do not get saved on Document.Save call

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...

OK, I found out that the Macro’s do appear be in the resulting document. The reason I didn’t think that they were there was because a custom menu did not show up in the resulting document…my mistake…

I’ll start another thread on that…

Hi

I want just refer to new thread you created.

https://forum.aspose.com/t/103641

Best regards.