VBA Macro
Contents
[
Hide
]
This article demonstrates how to add, access, and remove VBA macros using Aspose.Slides for Android via Java.
Add a VBA Macro
Create a presentation with a VBA project and a simple macro module.
static void addVbaMacro() {
Presentation presentation = new Presentation();
try {
presentation.setVbaProject(new VbaProject());
IVbaModule module = presentation.getVbaProject().getModules().addEmptyModule("Module");
module.setSourceCode("Sub Test()\n MsgBox \"Hi\" \nEnd Sub");
} finally {
presentation.dispose();
}
}
Access a VBA Macro
Retrieve the first module from the VBA project.
static void accessVbaMacro() {
Presentation presentation = new Presentation();
try {
presentation.setVbaProject(new VbaProject());
IVbaModule module = presentation.getVbaProject().getModules().addEmptyModule("Module");
module.setSourceCode("Sub Test()\n MsgBox \"Hi\" \nEnd Sub");
IVbaModule firstModule = presentation.getVbaProject().getModules().get_Item(0);
} finally {
presentation.dispose();
}
}
Remove a VBA Macro
Delete a module from the VBA project.
static void removeVbaMacro() {
Presentation presentation = new Presentation();
try {
presentation.setVbaProject(new VbaProject());
IVbaModule module = presentation.getVbaProject().getModules().addEmptyModule("Module");
module.setSourceCode("Sub Test()\n MsgBox \"Hi\" \nEnd Sub");
presentation.getVbaProject().getModules().remove(module);
} finally {
presentation.dispose();
}
}