VBA

Add VBA Macros

The Presentation class previous VbaProject property has been replaced. Now instead of the raw bytes of the VbaProject property representation of VBA project, the new IVbaProject interface implementation has been added. Use IVbaProject to manage VBA embedded in a presentation. You can add new project references, edit existing modules and create new ones. Also, you can create a new VBA project using the VbaProject class which implements the VbaProject interface. The following example shows how to create a simple VBA project. It contains one module and adds two required references to the libraries.

  1. Create an instance of the Presentation class.
  2. Add a new VbaProject with the Presentation.VbaProject property.
  3. Add a module to the VbaProject.
  4. Set the module source code.
  5. Add references to .
  6. Add references to Microsoft Office.
  7. Associate the references with the VbaProject.
  8. Finally, write the PPTX file using the Presentation object.

The implementation of the above steps is demonstrated in the example below.

Remove VBA Macros

The Presentation class now has included the support to remove the VBA macros inside presentation. The following example shows how to access and remove a VBA macro in presentation.

  1. Create an instance of the Presentation class and load presentation with Macro.
  2. Access the Macro module and remove that
  3. Finally, write the PPTX file using the Presentation class object.

The implementation of the above steps is demonstrated in the example below.

Extract VBA Macros

Aspose.Slides for .NET supports extracting VBA Macros from the slide. In order to extract VBA Macros, please follow the steps below:

  • Load a Presentation containing a VBA Macros
  • Check if Presentation contains VBA Project
  • Loop through all the modules that are contained in the VBA Project

The implementation of the above steps is demonstrated in the example below.