VbaModuleCollectionItem Property (Int32)

Retrieves a VbaModule object by index.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public VbaModule this[
	int index
] { get; }

Parameters

index
Type: SystemInt32
Zero-based index of the module to retrieve.

Property Value

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

// A VBA project inside the document is defined as a collection of VBA modules
VbaProject vbaProject = doc.VbaProject;
Console.WriteLine(vbaProject.IsSigned
    ? $"Project name: {vbaProject.Name} signed; Project code page: {vbaProject.CodePage}; Modules count: {vbaProject.Modules.Count()}\n"
    : $"Project name: {vbaProject.Name} not signed; Project code page: {vbaProject.CodePage}; 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
// You can retrieve object by integer or by name
vbaModules[0].SourceCode = "Your VBA code...";
vbaModules["Module1"].SourceCode = "Your VBA code...";

// Remove one of VbaModule from VbaModuleCollection
vbaModules.Remove(vbaModules[2]);
See Also