Guide about Macro Buttons in DOC/DOCX->PDF files

Macro Buttons

This guide explains the limitations and behavior of Macro Buttons in .doc and .docx files when converted to PDF using our conversion system.

 

Macro Buttons in Word

Macro Buttons are interactive elements inserted into Word documents to trigger VBA macros when clicked. They are typically created using: 

 

  • Field codes in the format { MACROBUTTON MacroName DisplayText }
  • ActiveX Controls tied to macro execution events

 

In Microsoft Word, Macro Buttons provide automation and interactivity for document users.

 

How to view MacroButton fields in Word:

  • Press Alt+F9 to toggle field codes on/off.
  • The field code will appear as:
    { MACROBUTTON MacroName DisplayText }

 

Why We Remove Macro Button Fields Before PDF Conversion

When converting .doc/.docx documents to PDF using Aspose.Words and Aspose.PDF.Drawing:

 

  • MacroButton fields lose all interactivity during PDF export.
  • The DisplayText inside a MacroButton field is treated as static document content.
  • If MacroButton fields are not removed, their DisplayText — even if normally invisible or system-related (e.g., HTMLDirect - may appear unexpectedly in the final PDF, resulting in unwanted visual artifacts.

 

To prevent this, we explicitly remove all Macro Button fields before conversion.

Code snippet for Macro Buttons removal:

foreach (var field in doc.Range.Fields
    .Where(f = f.Type == FieldType.FieldMacroButton)
    .ToArray())
{
    field.Remove();
}

 

Benefits of removal:

  • Ensures clean, static PDF output.
  • Prevents exposure of internal macro triggers or template artifacts.
  • Eliminates user confusion by removing non-functional elements.

 

Additional Notes

  • We preserve standard form fields (such as text inputs and checkboxes) where possible to maintain limited form functionality in the exported PDF.

     

  • ActiveX Controls are rendered as static content, as dynamic behavior is not preserved in PDF output.

 

Example

The attached Word sample file demonstrates the use of Macro Button fields.

 

Screenshot 2025-05-19 at 16.39.56.png


The corresponding generated PDF shows the final output after all Macro Button fields have been removed during the conversion process.

Attachments

Enlarged view