public void CreateNewVbaProject() { //ExStart //ExFor:VbaProject.#ctor //ExFor:VbaProject.Name //ExFor:VbaModule.#ctor //ExFor:VbaModule.Name //ExFor:VbaModule.Type //ExFor:VbaModule.SourceCode //ExFor:VbaModuleCollection.Add(VbaModule) //ExFor:VbaModuleType //ExSummary:Shows how to create a VbaProject from a scratch for using macros. 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"); //ExEnd project = new Document(ArtifactsDir + "Document.CreateVBAMacros.docm").VbaProject; Assert.AreEqual("Aspose.Project", project.Name); VbaModuleCollection modules = doc.VbaProject.Modules; Assert.AreEqual(2, modules.Count); Assert.AreEqual("ThisDocument", modules[0].Name); Assert.AreEqual(VbaModuleType.DocumentModule, modules[0].Type); Assert.Null(modules[0].SourceCode); Assert.AreEqual("Aspose.Module", modules[1].Name); Assert.AreEqual(VbaModuleType.ProceduralModule, modules[1].Type); Assert.AreEqual("New source code", modules[1].SourceCode); }
public void CreateNewVbaProject() { //ExStart //ExFor:VbaProject.#ctor //ExFor:VbaProject.Name //ExFor:VbaModule.#ctor //ExFor:VbaModule.Name //ExFor:VbaModule.Type //ExFor:VbaModule.SourceCode //ExFor:VbaModuleCollection.Add(VbaModule) //ExFor:VbaModuleType //ExSummary:Shows how to create a VbaProject from a scratch for using macros. 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"; module.Type = VbaModuleType.ProceduralModule; module.SourceCode = "New source code"; // Add module to the VBA project doc.VbaProject.Modules.Add(module); doc.Save(ArtifactsDir + "VbaProject.CreateVBAMacros.docm"); //ExEnd project = new Document(ArtifactsDir + "VbaProject.CreateVBAMacros.docm").VbaProject; Assert.AreEqual("Aspose.Project", project.Name); VbaModuleCollection modules = doc.VbaProject.Modules; Assert.AreEqual(2, modules.Count); Assert.AreEqual("ThisDocument", modules[0].Name); Assert.AreEqual(VbaModuleType.DocumentModule, modules[0].Type); Assert.Null(modules[0].SourceCode); Assert.AreEqual("Aspose.Module", modules[1].Name); Assert.AreEqual(VbaModuleType.ProceduralModule, modules[1].Type); Assert.AreEqual("New source code", modules[1].SourceCode); }