แมโคร VBA
Contents
[
Hide
]
บทความนี้แสดงวิธีการเพิ่ม, เข้าถึง, และลบแมโคร VBA โดยใช้ Aspose.Slides for Android via Java.
เพิ่มแมโคร VBA
สร้างงานนำเสนอพร้อมกับโปรเจกต์ VBA และโมดูลแมโครแบบง่าย
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();
}
}
เข้าถึงแมโคร VBA
ดึงโมดูลแรกจากโปรเจกต์ VBA
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();
}
}
ลบแมโคร VBA
ลบโมดูลจากโปรเจกต์ VBA
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();
}
}