VbaMacro
Contents
[
Hide
]
Illustrates how to add, access, and remove VBA macros using Aspose.Slides for PHP via Java.
Add a VBA Macro
Create a presentation with a VBA project and a simple macro module.
function addVbaMacro() {
$presentation = new Presentation();
try {
$presentation->setVbaProject(new VbaProject());
$module = $presentation->getVbaProject()->getModules()->addEmptyModule("Module");
$module->setSourceCode("Sub Test()\n MsgBox \"Hi\" \nEnd Sub");
$presentation->save("vba_macro.pptm", SaveFormat::Pptm);
} finally {
$presentation->dispose();
}
}
Access a VBA Macro
Retrieve the first module from the VBA project.
function accessVbaMacro() {
$presentation = new Presentation("vba_macro.pptm");
try {
$firstModule = $presentation->getVbaProject()->getModules()->get_Item(0);
} finally {
$presentation->dispose();
}
}
Remove a VBA Macro
Delete a module from the VBA project.
function removeVbaMacro() {
$presentation = new Presentation("vba_macro.pptm");
try {
// Assuming there is at least one module in the VBA project.
$module = $presentation->getVbaProject()->getModules()->get_Item(0);
$presentation->getVbaProject()->getModules()->remove($module);
$presentation->save("vba_macro_removed.pptm", SaveFormat::Pptm);
} finally {
$presentation->dispose();
}
}