Aspose.Cells kullanarak VBA veya Makro Kodunu Değiştirme

Contents
[ ]

Örnek

Aşağıdaki örnek kod, içinde belirtilen VBA veya Makro kodu bulunan kaynak Excel dosyasını yükler

 Sub Button1_Click()

MsgBox "This is test message."

End Sub

Aspose.Cells örnek kodunun yürütülmesinden sonra, VBA veya Makro kodu bu şekilde değiştirilmiş olacaktır

 Sub Button1_Click()

MsgBox "This is Aspose.Cells message."

End Sub

Kaynak Excel dosyasını ve çıkış Excel dosyasını verilen bağlantılardan indirebilirsiniz.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getDataDir(ModifyVBAorMacroCode.class);
// Create workbook object from source Excel file
Workbook workbook = new Workbook(dataDir + "sample.xlsm");
// Change the VBA Module Code
VbaModuleCollection modules = workbook.getVbaProject().getModules();
for (int i = 0; i < modules.getCount(); i++) {
VbaModule module = modules.get(i);
String code = module.getCodes();
// Replace the original message with the modified message
if (code.contains("This is test message.")) {
code = code.replace("This is test message.", "This is Aspose.Cells message.");
module.setCodes(code);
}
}
// Save the output Excel file
workbook.save(dataDir + "output.xlsm");