Reading VBA Information from MPP File
Aspose.Tasks for .NET API provides full support for reading VBA information from Microsoft Project MPP files. This includes working with project-level VBA data, modules, references, and module attributes. The VbaProject class is the central point for accessing VBA details, while the Modules and References collections allow deeper inspection of the project contents.
Reading VBA Project Information
The following example shows how to read general VBA project information using the VbaProject
and Project
classes. This snippet demonstrates how to load a project file and access its associated VBA project data.
1Project project = new Project("New Project.mpp");
2VbaProject vbaProject = project.VbaProject;
3Console.WriteLine("VbaProject.Name " + vbaProject.Name);
4Console.WriteLine("VbaProject.Description " + vbaProject.Description);
5Console.WriteLine("VbaProject.CompilationArguments " + vbaProject.CompilationArguments);
6Console.WriteLine("VbaProject.HelpContextId " + vbaProject.HelpContextId);
Reading References Information from VBA
The following example shows how to read VBA references using the VbaProject
, Project
, and VbaReference
classes. References contain external libraries or components that the VBA project depends on.
1Project project = new Project("New Project.mpp");
2
3VbaProject vbaProject = project.VbaProject;
4VbaReferenceCollection references = vbaProject.References;
5Console.WriteLine("Reference count ", references.Count);
6
7VbaReference reference = vbaProject.References.ToList()[0];
8Console.WriteLine("Identifier: " + reference.LibIdentifier);
9Console.WriteLine("Name: " + reference.Name);
10
11reference = vbaProject.References.ToList()[1];
12Console.WriteLine("Identifier: " + reference.LibIdentifier);
13Console.WriteLine("Name: " + reference.Name);
14
15reference = vbaProject.References.ToList()[2];
16Console.WriteLine("Identifier: " + reference.LibIdentifier);
17Console.WriteLine("Name: " + reference.Name);
Reading Modules Information from VBA
The following example demonstrates how to read module information from VBA projects. Modules contain VBA code that defines macros, procedures, and functions. You can access each module and its associated details programmatically.
1Project project = new Project("New Project.mpp");
2
3VbaProject vbaProject = project.VbaProject;
4Console.WriteLine("Total Modules Count: " + vbaProject.Modules.Count);
5
6IVbaModule vbaModule = vbaProject.Modules.ToList()[0];
7Console.WriteLine("Module Name: " + vbaModule.Name);
8Console.WriteLine("Source Code: " + vbaModule.SourceCode);
Reading Module Attributes Information from VBA
The following example shows how to read module attributes using the VbaProject
, Project
, and IVbaModule
classes. Attributes define additional properties of VBA modules such as descriptions, help context, or custom flags.
1Project project = new Project("New Project.mpp");
2VbaProject vbaProject = project.VbaProject;
3IVbaModule vbaModule = vbaProject.Modules.ToList()[0];
4
5Console.WriteLine("Attributes Count: " + vbaModule.Attributes.Count);
6Console.WriteLine("VB_Name: " + vbaModule.Attributes.ToList()[0].Key);
7Console.WriteLine("Module1: " + vbaModule.Attributes.ToList()[0].Value);
FAQ
Q: Do I need Microsoft Project installed to read VBA information?
- No. Aspose.Tasks for .NET can extract VBA data directly from MPP files without requiring Microsoft Project.
Q: Can I modify VBA code in MPP files using Aspose.Tasks for .NET?
- Currently, Aspose.Tasks for .NET allows reading VBA information, modules, and attributes, but it does not support editing VBA code.
Q: What type of VBA details can I extract from a project?
- You can read project-level VBA information, references to external libraries, modules containing code, and module-specific attributes.
Conclusion
Reading VBA information from Microsoft Project files with Aspose.Tasks for .NET is straightforward. You can programmatically access project-level VBA data, references, modules, and their attributes without Microsoft Project installed. This functionality is especially useful for auditing, reporting, or analyzing VBA-based automations within enterprise project files.