# VbaMacro

> Work with VBA macros in Python using Aspose.Slides: add or edit projects and modules, sign or remove macros, and save presentations in PPT, PPTX and ODP.

Source: https://docs.aspose.com/slides/python-net/examples/elements/vba-macro/
Updated: 2026-08-05


Illustrates how to add, access, and remove VBA macros using **Aspose.Slides for Python via .NET**.

## **Add a VBA Macro**

Create a presentation with a VBA project and a simple macro module.

```py
import aspose.slides as slides

def add_vba_macro():
    with slides.Presentation() as presentation:
        # Initialize a VBA project.
        presentation.vba_project = slides.vba.VbaProject()

        # Add an empty module named "Module".
        module = presentation.vba_project.modules.add_empty_module("Module")
        module.source_code = "Sub Test()\n MsgBox \"Hi\" \nEnd Sub"

        presentation.save("vba_macro.pptm", slides.export.SaveFormat.PPTM)
```

## **Access a VBA Macro**

Retrieve the first module from the VBA project.

```py
import aspose.slides as slides

def access_vba_macro():
    with slides.Presentation("vba_macro.pptm") as presentation:
        first_module = presentation.vba_project.modules[0]
```

## **Remove a VBA Macro**

Delete a module from the VBA project.

```py
import aspose.slides as slides

def remove_vba_macro():
    with slides.Presentation("vba_macro.pptm") as presentation:

        # Assuming the presentation contains a VBA project and at least one module.
        module = presentation.vba_project.modules[0]

        # Remove the module from the project.
        presentation.vba_project.modules.remove(module)

        presentation.save("vba_macro_removed.pptm", slides.export.SaveFormat.PPTM)
```

