com.aspose.words

Class VbaModuleCollection

  • java.lang.Object
    • com.aspose.words.VbaModuleCollection
  • All Implemented Interfaces:
    java.lang.Iterable
    public class VbaModuleCollection 
    extends java.lang.Object

Represents a collection of VbaModule objects.

Example:

Shows how to access a document's VBA project information.
Document doc = new Document(getMyDir() + "VBA project.docm");

// A VBA project contains a collection of VBA modules.
VbaProject vbaProject = doc.getVbaProject();
System.out.println(vbaProject.isSigned()
        ? MessageFormat.format("Project name: {0} signed; Project code page: {1}; Modules count: {2}\n", vbaProject.getName(), vbaProject.getCodePage(), vbaProject.getModules().getCount())
        : MessageFormat.format("Project name: {0} not signed; Project code page: {1}; Modules count: {2}\n", vbaProject.getName(), vbaProject.getCodePage(), vbaProject.getModules().getCount()));

VbaModuleCollection vbaModules = doc.getVbaProject().getModules();

Assert.assertEquals(vbaModules.getCount(), 3);

for (VbaModule module : vbaModules) {
    System.out.println(MessageFormat.format("Module name: {0};\nModule code:\n{1}\n", module.getName(), module.getSourceCode()));
}

// Set new source code for VBA module. You can access VBA modules in the collection either by index or by name.
vbaModules.get(0).setSourceCode("Your VBA code...");
vbaModules.get("Module1").setSourceCode("Your VBA code...");

// Remove a module from the collection.
vbaModules.remove(vbaModules.get(2));

Property Getters/Setters Summary
intgetCount()
Returns the number of VBA modules in the collection.
VbaModuleget(int index)
Retrieves a VbaModule object by index.
VbaModuleget(java.lang.String name)
Retrieves a VbaModule object by name, or Null if not found.
 
Method Summary
voidadd(VbaModule vbaModule)
Adds a module to the collection.
voidremove(VbaModule module)
Removes the specified module from the collection.
 

    • Property Getters/Setters Detail

      • getCount

        public int getCount()
        
        Returns the number of VBA modules in the collection.

        Example:

        Shows how to access a document's VBA project information.
        Document doc = new Document(getMyDir() + "VBA project.docm");
        
        // A VBA project contains a collection of VBA modules.
        VbaProject vbaProject = doc.getVbaProject();
        System.out.println(vbaProject.isSigned()
                ? MessageFormat.format("Project name: {0} signed; Project code page: {1}; Modules count: {2}\n", vbaProject.getName(), vbaProject.getCodePage(), vbaProject.getModules().getCount())
                : MessageFormat.format("Project name: {0} not signed; Project code page: {1}; Modules count: {2}\n", vbaProject.getName(), vbaProject.getCodePage(), vbaProject.getModules().getCount()));
        
        VbaModuleCollection vbaModules = doc.getVbaProject().getModules();
        
        Assert.assertEquals(vbaModules.getCount(), 3);
        
        for (VbaModule module : vbaModules) {
            System.out.println(MessageFormat.format("Module name: {0};\nModule code:\n{1}\n", module.getName(), module.getSourceCode()));
        }
        
        // Set new source code for VBA module. You can access VBA modules in the collection either by index or by name.
        vbaModules.get(0).setSourceCode("Your VBA code...");
        vbaModules.get("Module1").setSourceCode("Your VBA code...");
        
        // Remove a module from the collection.
        vbaModules.remove(vbaModules.get(2));
      • get

        public VbaModule get(int index)
        
        Retrieves a VbaModule object by index.
        Parameters:
        index - Zero-based index of the module to retrieve.

        Example:

        Shows how to access a document's VBA project information.
        Document doc = new Document(getMyDir() + "VBA project.docm");
        
        // A VBA project contains a collection of VBA modules.
        VbaProject vbaProject = doc.getVbaProject();
        System.out.println(vbaProject.isSigned()
                ? MessageFormat.format("Project name: {0} signed; Project code page: {1}; Modules count: {2}\n", vbaProject.getName(), vbaProject.getCodePage(), vbaProject.getModules().getCount())
                : MessageFormat.format("Project name: {0} not signed; Project code page: {1}; Modules count: {2}\n", vbaProject.getName(), vbaProject.getCodePage(), vbaProject.getModules().getCount()));
        
        VbaModuleCollection vbaModules = doc.getVbaProject().getModules();
        
        Assert.assertEquals(vbaModules.getCount(), 3);
        
        for (VbaModule module : vbaModules) {
            System.out.println(MessageFormat.format("Module name: {0};\nModule code:\n{1}\n", module.getName(), module.getSourceCode()));
        }
        
        // Set new source code for VBA module. You can access VBA modules in the collection either by index or by name.
        vbaModules.get(0).setSourceCode("Your VBA code...");
        vbaModules.get("Module1").setSourceCode("Your VBA code...");
        
        // Remove a module from the collection.
        vbaModules.remove(vbaModules.get(2));
      • get

        public VbaModule get(java.lang.String name)
        
        Retrieves a VbaModule object by name, or Null if not found.

        Example:

        Shows how to access a document's VBA project information.
        Document doc = new Document(getMyDir() + "VBA project.docm");
        
        // A VBA project contains a collection of VBA modules.
        VbaProject vbaProject = doc.getVbaProject();
        System.out.println(vbaProject.isSigned()
                ? MessageFormat.format("Project name: {0} signed; Project code page: {1}; Modules count: {2}\n", vbaProject.getName(), vbaProject.getCodePage(), vbaProject.getModules().getCount())
                : MessageFormat.format("Project name: {0} not signed; Project code page: {1}; Modules count: {2}\n", vbaProject.getName(), vbaProject.getCodePage(), vbaProject.getModules().getCount()));
        
        VbaModuleCollection vbaModules = doc.getVbaProject().getModules();
        
        Assert.assertEquals(vbaModules.getCount(), 3);
        
        for (VbaModule module : vbaModules) {
            System.out.println(MessageFormat.format("Module name: {0};\nModule code:\n{1}\n", module.getName(), module.getSourceCode()));
        }
        
        // Set new source code for VBA module. You can access VBA modules in the collection either by index or by name.
        vbaModules.get(0).setSourceCode("Your VBA code...");
        vbaModules.get("Module1").setSourceCode("Your VBA code...");
        
        // Remove a module from the collection.
        vbaModules.remove(vbaModules.get(2));
    • Method Detail

      • add

        public void add(VbaModule vbaModule)
        Adds a module to the collection.
      • remove

        public void remove(VbaModule module)
        Removes the specified module from the collection.
        Parameters:
        module - The module to remove.

        Example:

        Shows how to access a document's VBA project information.
        Document doc = new Document(getMyDir() + "VBA project.docm");
        
        // A VBA project contains a collection of VBA modules.
        VbaProject vbaProject = doc.getVbaProject();
        System.out.println(vbaProject.isSigned()
                ? MessageFormat.format("Project name: {0} signed; Project code page: {1}; Modules count: {2}\n", vbaProject.getName(), vbaProject.getCodePage(), vbaProject.getModules().getCount())
                : MessageFormat.format("Project name: {0} not signed; Project code page: {1}; Modules count: {2}\n", vbaProject.getName(), vbaProject.getCodePage(), vbaProject.getModules().getCount()));
        
        VbaModuleCollection vbaModules = doc.getVbaProject().getModules();
        
        Assert.assertEquals(vbaModules.getCount(), 3);
        
        for (VbaModule module : vbaModules) {
            System.out.println(MessageFormat.format("Module name: {0};\nModule code:\n{1}\n", module.getName(), module.getSourceCode()));
        }
        
        // Set new source code for VBA module. You can access VBA modules in the collection either by index or by name.
        vbaModules.get(0).setSourceCode("Your VBA code...");
        vbaModules.get("Module1").setSourceCode("Your VBA code...");
        
        // Remove a module from the collection.
        vbaModules.remove(vbaModules.get(2));