DocumentVbaProject Property
Gets or sets a VbaProject.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 20.1
public VbaProject VbaProject { get; set; }

Property Value

Type: VbaProject
Shows how to get access to VBA project information in the document.
Document doc = new Document(MyDir + "Document.TestButton.docm");

// A VBA project inside the document is defined as a collection of VBA modules
VbaProject vbaProject = doc.VbaProject;
Console.WriteLine($"Project name: {vbaProject.Name}; Modules count: {vbaProject.Modules.Count()}\n");

VbaModuleCollection vbaModules = doc.VbaProject.Modules;
foreach (VbaModule module in vbaModules)
    Console.WriteLine($"Module name: {module.Name};\nModule code:\n{module.SourceCode}\n");

// Set new source code for VBA module
string oldCode = vbaModules[0].SourceCode;
vbaModules[0].SourceCode = "Your VBA code...";

vbaModules[0].SourceCode = oldCode;
See Also