VBA‑макрос

В этой статье демонстрируется, как добавлять, получать доступ и удалять VBA-макросы с помощью Aspose.Slides for Node.js via Java.

Добавить VBA-макрос

Создайте презентацию с проектом VBA и простым модулем макроса.

function addVbaMacro() {
    let presentation = new aspose.slides.Presentation();
    try {
        presentation.setVbaProject(new aspose.slides.VbaProject());

        let module = presentation.getVbaProject().getModules().addEmptyModule("Module");
        module.setSourceCode("Sub Test()\n MsgBox \"Hi\" \nEnd Sub");

        presentation.save("vba_macro.pptm", aspose.slides.SaveFormat.Pptm);
    } finally {
        presentation.dispose();
    }
}

Получить доступ к VBA-макросу

Получите первый модуль из проекта VBA.

function accessVbaMacro() {
    let presentation = new aspose.slides.Presentation("vba_macro.pptm");
    try {
        // Предполагая, что презентация содержит как минимум один модуль VBA.
        let firstModule = presentation.getVbaProject().getModules().get_Item(0);
    } finally {
        presentation.dispose();
    }
}

Удалить VBA-макрос

Удалите модуль из проекта VBA.

function removeVbaMacro() {
    let presentation = new aspose.slides.Presentation("vba_macro.pptm");
    try {
        // Предполагая, что презентация содержит как минимум один модуль VBA.
        let firstModule = presentation.getVbaProject().getModules().get_Item(0);

        presentation.getVbaProject().getModules().remove(firstModule);

        presentation.save("vba_macro_removed.pptm", aspose.slides.SaveFormat.Pptm);
    } finally {
        presentation.dispose();
    }
}