Macro VBA
Contents
[
Hide
]
Minh họa cách thêm, truy cập và xóa macro VBA bằng Aspose.Slides for PHP via Java.
Thêm macro VBA
Tạo một bản trình chiếu có dự án VBA và một mô-đun macro đơn giản.
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();
}
}
Truy cập macro VBA
Lấy mô-đun đầu tiên từ dự án VBA.
function accessVbaMacro() {
$presentation = new Presentation("vba_macro.pptm");
try {
$firstModule = $presentation->getVbaProject()->getModules()->get_Item(0);
} finally {
$presentation->dispose();
}
}
Xóa macro VBA
Xóa một mô-đun khỏi dự án VBA.
function removeVbaMacro() {
$presentation = new Presentation("vba_macro.pptm");
try {
// Giả sử có ít nhất một mô-đun trong dự án VBA.
$module = $presentation->getVbaProject()->getModules()->get_Item(0);
$presentation->getVbaProject()->getModules()->remove($module);
$presentation->save("vba_macro_removed.pptm", SaveFormat::Pptm);
} finally {
$presentation->dispose();
}
}