Working with VBA Macros
Visual Basic for Applications (VBA) for Microsoft Word is a simple but powerful programming language that can be used to extend the functionality. Aspose.Words API provides three classes to get access to the VBA project source code:
- The VBAProject class provides access to VBA project information
- The VBAModuleCollection class returns the collection of VBA project modules
- The VbaModule class provides access to the VBA project module
- The VbaModuleType enumeration defines the types of a model in a VBA project. The module can be a procedural module, document module, class module, or designer module
Creating a VBA Project
Aspose.Words API provides the Dcoument.VbaProject property to get or set VbaProject in the document. The following code example shows how to create a VBA project and VBA Module along with basic properties e.g. Name and Type.
The following code example demonstrates how to read VBA Macros from the document.
Write or Modify Macros
The following code example shows how to modify VBA Macros using the VbaModule.SourceCode property.
Clone VBA Project
The following code example demonstrates how to clone the VBA Project using the VbaProject.Clone property which creates a copy of the existing project.
Clone VBA Module
The following code example demonstrates how to clone the VBA Module using the VbaModule.Clone property which creates a copy of the existing project.
Working with the VBA Project References
Aspose.Words API provides VbaReferenceCollection class to work with VBA Project References representing a collection of VBA project references. The following code example demonstrates how to remove some references from the collection of references from a VBA project.