Aspose::Words::Vba::VbaModuleCollection class
Contents
[
Hide
]VbaModuleCollection class
Represents a collection of VbaModule objects. To learn more, visit the Working with VBA Macros documentation article.
class VbaModuleCollection : public System::Collections::Generic::IEnumerable<System::SharedPtr<Aspose::Words::Vba::VbaModule>>
Methods
| Method | Description |
|---|---|
| Add(const System::SharedPtr<Aspose::Words::Vba::VbaModule> &) | Adds a module to the collection. |
| Remove(const System::SharedPtr<Aspose::Words::Vba::VbaModule> &) | Removes the specified module from the collection. |
| get_Count() | Returns the number of VBA modules in the collection. |
| idx_get(const System::String &) | Retrieves a VbaModule object by name, or Null if not found. |
| idx_get(int32_t) | Retrieves a VbaModule object by index. |
Typedefs
| Typedef | Description |
|---|---|
| const_iterator | Const iterator type. |
| iterator | Iterator type. |
| iterator_holder_type | A collection type whose iterator types is used as iterator types in the current collection. |
| virtualized_iterator | Virtualized type. |
| virtualized_iterator_element | Virtualized element type. |
Examples
Shows how to access a document’s VBA project information.
auto doc = System::MakeObject<Aspose::Words::Document>(System::String(get_MyDir() + u"VBA project.docm"));
// A VBA project contains a collection of VBA modules.
System::SharedPtr<Aspose::Words::Vba::VbaProject> vbaProject = doc->get_VbaProject();
std::cout << (vbaProject->get_IsSigned() ? System::String::Format(u"Project name: {0} signed; Project code page: {1}; Modules count: {2}\n", vbaProject->get_Name(), vbaProject->get_CodePage(), vbaProject->get_Modules()->LINQ_Count()) : System::String::Format(u"Project name: {0} not signed; Project code page: {1}; Modules count: {2}\n", vbaProject->get_Name(), vbaProject->get_CodePage(), vbaProject->get_Modules()->LINQ_Count())) << std::endl;
System::SharedPtr<Aspose::Words::Vba::VbaModuleCollection> vbaModules = doc->get_VbaProject()->get_Modules();
ASSERT_EQ(3, vbaModules->LINQ_Count());
for (auto&& module_ : vbaModules)
{
std::cout << System::String::Format(u"Module name: {0};\nModule code:\n{1}\n", module_->get_Name(), module_->get_SourceCode()) << std::endl;
}
// Set new source code for VBA module. You can access VBA modules in the collection either by index or by name.
vbaModules->idx_get(0)->set_SourceCode(u"Your VBA code...");
vbaModules->idx_get(u"Module1")->set_SourceCode(u"Your VBA code...");
// Remove a module from the collection.
vbaModules->Remove(vbaModules->idx_get(2));
See Also
- Namespace Aspose::Words::Vba
- Library Aspose.Words for C++