Reading VBA Information from MPP file

Aspose.Tasks for C++ API provides support for reading VBA information from 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 code example demonstrates how to read VBA Project Information with the help of VbaProject and Project class.

1// Loading project file
2System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"VbaProject1.mpp");
3    
4System::SharedPtr<VbaProject> vbaProject = project->get_VbaProject();
5    
6System::Console::WriteLine(System::String(u"VbaProject.Name ") + vbaProject->get_Name());
7System::Console::WriteLine(System::String(u"VbaProject.Description ") + vbaProject->get_Description());
8System::Console::WriteLine(System::String(u"VbaProject.CompilationArguments") + vbaProject->get_CompilationArguments());
9System::Console::WriteLine(System::String(u"VbaProject.HelpContextId") + vbaProject->get_HelpContextId());

Reading References Information from VBA

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

 1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"VbaProject1.mpp");
 2    
 3System::SharedPtr<VbaProject> vbaProject = project->get_VbaProject();
 4System::SharedPtr<VbaReferenceCollection> references = vbaProject->get_References();
 5System::Console::WriteLine(u"Reference count ", System::ObjectExt::Box<int32_t>(references->get_Count()));
 6    
 7System::SharedPtr<VbaReference> reference = vbaProject->get_References()->ToList()->idx_get(0);
 8System::Console::WriteLine(System::String(u"Identifier: ") + reference->get_LibIdentifier());
 9System::Console::WriteLine(System::String(u"Name: ") + reference->get_Name());
10    
11reference = vbaProject->get_References()->ToList()->idx_get(1);
12System::Console::WriteLine(System::String(u"Identifier: ") + reference->get_LibIdentifier());
13System::Console::WriteLine(System::String(u"Name: ") + reference->get_Name());
14    
15reference = vbaProject->get_References()->ToList()->idx_get(2);
16System::Console::WriteLine(System::String(u"Identifier: ") + reference->get_LibIdentifier());
17System::Console::WriteLine(System::String(u"Name: ") + reference->get_Name());

Reading Modules Information from VBA

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

1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"VbaProject1.mpp");
2    
3System::SharedPtr<VbaProject> vbaProject = project->get_VbaProject();
4System::Console::WriteLine(System::String(u"Total Modules Count: ") + vbaProject->get_Modules()->get_Count());
5    
6System::SharedPtr<IVbaModule> vbaModule = vbaProject->get_Modules()->ToList()->idx_get(0);
7System::Console::WriteLine(System::String(u"Module Name: ") + vbaModule->get_Name());
8System::Console::WriteLine(System::String(u"Source Code: ") + vbaModule->get_SourceCode());

Reading Module Attributes Information from VBA

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

1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"VbaProject1.mpp");
2System::SharedPtr<VbaProject> vbaProject = project->get_VbaProject();
3System::SharedPtr<IVbaModule> vbaModule = vbaProject->get_Modules()->ToList()->idx_get(0);
4    
5System::Console::WriteLine(System::String(u"Attributes Count: ") + vbaModule->get_Attributes()->get_Count());
6System::Console::WriteLine(System::String(u"VB_Name: ") + vbaModule->get_Attributes()->ToList()->idx_get(0)->get_Key());
7System::Console::WriteLine(System::String(u"Module1: ") + vbaModule->get_Attributes()->ToList()->idx_get(0)->get_Value());
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.