DocumentHasMacros Property
Returns true if the document has a VBA project (macros).

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.9
Syntax
public bool HasMacros { get; }

Property Value

Type: Boolean
Remarks
Examples
Shows how to use MACROBUTTON fields that enable us to run macros by clicking.
[C#]

// Open a document that contains macros
Document doc = new Document(MyDir + "Document.HasMacro.docm");
DocumentBuilder builder = new DocumentBuilder(doc);
Assert.IsTrue(doc.HasMacros);

// Insert a MACROBUTTON field and reference by name a macro that exists within the input document
FieldMacroButton field = (FieldMacroButton)builder.InsertField(FieldType.FieldMacroButton, true);
field.MacroName = "MyMacro";
field.DisplayText = "Double click to run macro: " + field.MacroName;

Assert.AreEqual(" MACROBUTTON  MyMacro Double click to run macro: MyMacro", field.GetFieldCode());

builder.InsertParagraph();

// Reference "ViewZoom200", a macro that was shipped with Microsoft Word, found under "Word commands"
// If our document has a macro of the same name as one from another source, the field will select ours to run
field = (FieldMacroButton)builder.InsertField(FieldType.FieldMacroButton, true);
field.MacroName = "ViewZoom200";
field.DisplayText = "Run " + field.MacroName;

Assert.AreEqual(" MACROBUTTON  ViewZoom200 Run ViewZoom200", field.GetFieldCode());

// Save the document as a macro-enabled document type
doc.Save(ArtifactsDir + "Field.MacroButton.docm");
See Also