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

Free Support Forum - aspose.com

Insert document using mail merge at macro button

I have a question about inserting document while we use mail merge.

We like to use macro-button because all our templates are build so, and we can add some extra info in the button.

Everythinks works, but when I try to insert a document this document is not inserted at the macro-button, but on top of the document.

The button it self is not removed form the base template.

I have attached a sample using merge-field which is working well and a sample using macro-buttons with the problems.

Hi Egbert,

Thanks for your inquiry. You can achieve this by using the following code:
Document doc = new Document(getMyDir() + “Testletter_macro.doc”);

NodeCollection starts = doc.getChildNodes(NodeType.FIELD_START, true);
for(FieldStart start : (Iterable<FieldStart>) starts){
if(start.getFieldType() == FieldType.FIELD_MACRO_BUTTON){
Paragraph parentPara = (Paragraph) start.getAncestor(NodeType.PARAGRAPH);
if (parentPara != null){
insertDocument(parentPara, new Document());

doc.save(getMyDir() + “out.docx”);

I hope, this helps.

Best regards,