VbaModule Class

Provides access to VBA project module.
Inheritance Hierarchy
SystemObject
  Aspose.WordsVbaModule

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public class VbaModule

The VbaModule type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleVbaModule
Creates an empty module.
Properties
  NameDescription
Public propertyCode exampleName
Gets or sets VBA project module name.
Public propertyCode exampleSourceCode
Gets or sets VBA project module source code.
Public propertyCode exampleType
Specifies whether the module is a procedural module, document module, class module, or designer module.
Methods
  NameDescription
Public methodCode exampleClone
Performs a copy of the VbaModule.
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)
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