VbaProject Class

Provides access to VBA project information. A VBA project inside the document is defined as a collection of VBA modules.

Inheritance Hierarchy

SystemObject
  Aspose.WordsVbaProject

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.9.0

Syntax

public class VbaProject

The VbaProject type exposes the following members.

Constructors

  NameDescription
Public methodCode exampleVbaProject
Creates a blank VbaProject.

Properties

  NameDescription
Public propertyCode exampleCodePage
Returns the VBA project’s code page.
Public propertyCode exampleIsSigned
Shows whether the VbaProject is signed or not.
Public propertyCode exampleModules
Returns collection of VBA project modules.
Public propertyCode exampleName
Gets or sets VBA project name.
Public propertyReferences
Gets a collection of VBA project references.

Methods

  NameDescription
Public methodCode exampleClone
Performs a copy of the VbaProject.
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)

Examples

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;
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; 

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]);

See Also