Reading VBA Information from MPP File

Aspose.Tasks for Java API provides support for reading VBA information from the MPP file. This includes working with:

The VbaProject class is the main class for reading the VBA information from the project file. This further has Modules and References collection for reading further details of the VBA project file. This article demonstrates the usage of all these with the help of code samples.

Reading VBA Project Information

The following example shows how to read VBA Project Information with the help of VbaProject and Project class

1// Load project file
2Project project = new Project(dataDir + "VbaProject1.mpp");
3
4VbaProject vbaProject = project.getVbaProject();
5
6System.out.println("VbaProject.Name " + vbaProject.getName());
7System.out.println("VbaProject.Description " + vbaProject.getDescription());
8System.out.println("VbaProject.CompilationArguments" + vbaProject.getCompilationArguments());
9System.out.println("VbaProject.HelpContextId" + vbaProject.getHelpContextId());

Reading References Information from VBA

The following example shows how to read VBA References Information from VBA with the help of VbaProject, Project and VbaReference class

 1// Load project file
 2Project project = new Project(dataDir + "VbaProject1.mpp");
 3
 4VbaProject vbaProject = project.getVbaProject();
 5VbaReferenceCollection references = vbaProject.getReferences();
 6System.out.println("Reference count "+ references.size());
 7
 8VbaReference reference = vbaProject.getReferences().toList().get(0);
 9System.out.println("Identifier: " + reference.getLibIdentifier());
10System.out.println("Name: " + reference.getName());
11
12reference = vbaProject.getReferences().toList().get(1);
13System.out.println("Identifier: " + reference.getLibIdentifier());
14System.out.println("Name: " + reference.getName());
15
16reference = vbaProject.getReferences().toList().get(2);
17System.out.println("Identifier: " + reference.getLibIdentifier());
18System.out.println("Name: " + reference.getName());

Reading Modules Information from VBA

The following example shows how to read modules information from VBA with the help of VbaProject, Project and IVbaModule class

1// Load project file
2Project project = new Project(dataDir + "VbaProject1.mpp");
3
4VbaProject vbaProject = project.getVbaProject();
5System.out.println("Total Modules Count: " + vbaProject.getModules().size());
6
7IVbaModule vbaModule = vbaProject.getModules().toList().get(0);
8System.out.println("Module Name: " + vbaModule.getName());
9System.out.println("Source Code: " + vbaModule.getSourceCode());

Reading Module Attributes Information from VBA

The following example shows how to read modules attributes from VBA with the help of VbaProject, Project and IVbaModule class.

1// Load project file
2Project project = new Project(dataDir + "VbaProject1.mpp");
3        
4VbaProject vbaProject = project.getVbaProject();
5IVbaModule vbaModule = vbaProject.getModules().toList().get(0);
6
7System.out.println("Attributes Count: " + vbaModule.getAttributes().size());
8System.out.println("VB_Name: " + vbaModule.getAttributes().toList().get(0).getKey());
9System.out.println("Module1: " + vbaModule.getAttributes().toList().get(0).getValue());
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.