VbaModuleName Property |
Namespace: Aspose.Words
Document doc = new Document(MyDir + "VBA project.docm"); // A VBA project inside the document is defined as a collection of VBA modules VbaProject vbaProject = doc.VbaProject; Console.WriteLine(vbaProject.IsSigned ? $"Project name: {vbaProject.Name} signed; Project code page: {vbaProject.CodePage}; Modules count: {vbaProject.Modules.Count()}\n" : $"Project name: {vbaProject.Name} not signed; Project code page: {vbaProject.CodePage}; Modules count: {vbaProject.Modules.Count()}\n"); VbaModuleCollection vbaModules = doc.VbaProject.Modules; foreach (VbaModule module in vbaModules) Console.WriteLine($"Module name: {module.Name};\nModule code:\n{module.SourceCode}\n"); // Set new source code for VBA module // You can retrieve object by integer or by name vbaModules[0].SourceCode = "Your VBA code..."; vbaModules["Module1"].SourceCode = "Your VBA code..."; // Remove one of VbaModule from VbaModuleCollection vbaModules.Remove(vbaModules[2]);
Document doc = new Document(); // Create a new VBA project VbaProject project = new VbaProject(); project.Name = "Aspose.Project"; doc.VbaProject = project; // Create a new module and specify a macro source code VbaModule module = new VbaModule(); module.Name = "Aspose.Module"; // VbaModuleType values: // procedural module - A collection of subroutines and functions // ------ // document module - A type of VBA project item that specifies a module for embedded macros and programmatic access // operations that are associated with a document // ------ // class module - A module that contains the definition for a new object. Each instance of a class creates // a new object, and procedures that are defined in the module become properties and methods of the object // ------ // designer module - A VBA module that extends the methods and properties of an ActiveX control that has been // registered with the project module.Type = VbaModuleType.ProceduralModule; module.SourceCode = "New source code"; // Add module to the VBA project doc.VbaProject.Modules.Add(module); doc.Save(ArtifactsDir + "Document.CreateVBAMacros.docm");