I have word template that contains a macro, when i process it through the Aspose word component the macro is lost. The template i use that contains the macro is used to generate in most cases more then one document and these documents are then combined together.
Also is there anyway to run a macro on a document after the merge fields are populated?
So is the macro missed in the combined document or directly in the attached document after executing mail merge and saving to disk? I’ve just tested it and no macros were lost after saving.
With respect to your second question, we do not allow to run macros programmatically using Aspose.Word due to security reasons.
It is expected since you move document content only, not common document data like macros. We wouldn’t want to deal with macros separately as I posted above. So a possible workaround would be as follows: use this document as the destination document and add other document sections to it; of course, clear its content to make it blank first using Document.RemoveAllChildren.
I am using a clone of the document as a destination document. When generating 1 document with 1 set of xml it works fine, keeps the macro.
The problem arises when i append other documents to the first one. This is when the macro is lost. It is not stored on the final multi document consisting of more than one page.
I hope i made myself a little more clearer this time round
No it doesn’t seem to be the cause. However, something weird is happening with your document, I’m experiencing problems with adding sections to it when trying to reproduce the issue… I’m not sure what’s going on at the moment, it definitely requires further investigation so I’m logging it in the meantime. Please check back later, probably next week.
Please post more code, especially a fragment in which you create (or clone) the destination document. Also, attach other documents involved in the merge. Thanks.
// Take clone of Word template and assign to output document
docOutput = docWordTemplate.Clone();
Heres the code i use if i know the Final document is going to have other docs appended to it.
protected override object PreProcess(XmlDocument xmlRequest, XmlTextWriter xmlOutput)
{
Document docMulti = null;
string strOutputDocumentFrequency = xmlRequest.SelectSingleNode(@"//Output/Frequency").InnerText;
// If all document items are to be output to a single document
if (strOutputDocumentFrequency == "Multi")
{
docMulti = new Document();
// Removes default blank section from new word document
docMulti.Sections.RemoveAt(0);
}
return docMulti;
}
protected override void PostProcess(object objMulti, string strOutputFile, XmlDocument xmlRequest, XmlTextWriter xmlOutput)
{
string strOutputDocumentFrequency = xmlRequest.SelectSingleNode(@"//Output/Frequency").InnerText;
// If all document items are to be output to a single document
if (strOutputDocumentFrequency == "Multi")
{
Document docMulti = (Document)objMulti;
docMulti.Save(strOutputFile + ".doc", SaveFormat.FormatDocument);
xmlOutput.WriteElementString("File", strOutputFile + ".doc");
}
}
I’ve also attached the input xml and my current output (without the macro)