VbaModule Class

Provides access to VBA project module.

ExpandedInheritance Hierarchy

SystemObject
  Aspose.Words.VbaVbaModule

Namespace:  Aspose.Words.Vba
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 22.1.0

ExpandedSyntax

public class VbaModule

The VbaModule type exposes the following members.

ExpandedConstructors

  NameDescription
Public methodCode exampleVbaModule
Creates an empty module.

ExpandedProperties

  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.

ExpandedMethods

  NameDescription
Public methodCode exampleClone
Performs a copy of the VbaModule.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)

ExpandedExamples

Shows how to access a document's VBA project information.
Document doc = new Document(MyDir + "VBA project.docm");

// A VBA project contains a collection of VBA modules.
VbaProject vbaProject = doc.VbaProject;
    ? $"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; 

Assert.AreEqual(vbaModules.Count(), 3);

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 access VBA modules in the collection either by index or by name.
vbaModules[0].SourceCode = "Your VBA code...";
vbaModules["Module1"].SourceCode = "Your VBA code...";

// Remove a module from the collection.
vbaModules.Remove(vbaModules[2]);

ExpandedSee Also