com.aspose.words

Class VbaModule

  • java.lang.Object
    • com.aspose.words.VbaModule
  • All Implemented Interfaces:
    java.lang.Cloneable
    public class VbaModule 
    extends java.lang.Object

Provides access to VBA project module.

Example:

Shows how to get access to VBA project information in the document.
Document doc = new Document(getMyDir() + "Document.TestButton.docm");

// A VBA project inside the document is defined as a collection of VBA modules
VbaProject vbaProject = doc.getVbaProject();

VbaModuleCollection vbaModules = doc.getVbaProject().getModules();
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
String oldCode = vbaModules.get(0).getSourceCode();
vbaModules.get(0).setSourceCode("Your VBA code...");

vbaModules.get(0).setSourceCode(oldCode);

Constructor Summary
VbaModule()
Creates an empty module.
 
Property Getters/Setters Summary
java.lang.StringgetName()
void
setName(java.lang.Stringvalue)
           Gets or sets VBA project module name.
java.lang.StringgetSourceCode()
void
setSourceCode(java.lang.Stringvalue)
           Gets or sets VBA project module source code.
intgetType()
void
setType(intvalue)
           Specifies whether the module is a procedural module, document module, class module, or designer module. The value of the property is VbaModuleType integer constant.
 
Method Summary
VbaModuledeepClone()
Performs a copy of the VbaModule.
 

    • Constructor Detail

      • VbaModule

        public VbaModule()
        Creates an empty module.
    • Property Getters/Setters Detail

      • getName/setName

        public java.lang.String getName() / public void setName(java.lang.String value)
        
        Gets or sets VBA project module name.

        Example:

        Shows how to get access to VBA project information in the document.
        Document doc = new Document(getMyDir() + "Document.TestButton.docm");
        
        // A VBA project inside the document is defined as a collection of VBA modules
        VbaProject vbaProject = doc.getVbaProject();
        
        VbaModuleCollection vbaModules = doc.getVbaProject().getModules();
        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
        String oldCode = vbaModules.get(0).getSourceCode();
        vbaModules.get(0).setSourceCode("Your VBA code...");
        
        vbaModules.get(0).setSourceCode(oldCode);
      • getSourceCode/setSourceCode

        public java.lang.String getSourceCode() / public void setSourceCode(java.lang.String value)
        
        Gets or sets VBA project module source code.

        Example:

        Shows how to get access to VBA project information in the document.
        Document doc = new Document(getMyDir() + "Document.TestButton.docm");
        
        // A VBA project inside the document is defined as a collection of VBA modules
        VbaProject vbaProject = doc.getVbaProject();
        
        VbaModuleCollection vbaModules = doc.getVbaProject().getModules();
        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
        String oldCode = vbaModules.get(0).getSourceCode();
        vbaModules.get(0).setSourceCode("Your VBA code...");
        
        vbaModules.get(0).setSourceCode(oldCode);
      • getType/setType

        public int getType() / public void setType(int value)
        
        Specifies whether the module is a procedural module, document module, class module, or designer module. The value of the property is VbaModuleType integer constant.
    • Method Detail

      • deepClone

        public VbaModule deepClone()
        Performs a copy of the VbaModule.
        Returns:
        The cloned VbaModule.