search/mag_sel search/close
Aspose::Words::Vba Namespace Reference

The Aspose.Words.Vba namespace provides classes to work with VBA projects.

A VbaProject inside the document is defined as a collection of VbaModule.

Classes

class  VbaModule
 Provides access to VBA project module. More...
 
class  VbaModuleCollection
 Represents a collection of VbaModule objects. More...
 
class  VbaProject
 Provides access to VBA project information. A VBA project inside the document is defined as a collection of VBA modules. More...
 
class  VbaReference
 Implements a reference to an Automation type library or VBA project. More...
 
class  VbaReferenceCollection
 Represents a collection of VbaReference objects. More...
 

Enumerations

enum class  VbaModuleType
 Specifies the type of a model in a VBA project. More...
 
enum class  VbaReferenceType
 Allows to specify the type of a VbaReference object. More...
 

Enumeration Type Documentation

◆ VbaModuleType

Specifies the type of a model in a VBA project.

Examples

Shows how to create a VBA project using macros.

auto doc = MakeObject<Document>();
// Create a new VBA project.
auto project = MakeObject<VbaProject>();
project->set_Name(u"Aspose.Project");
doc->set_VbaProject(project);
// Create a new module and specify a macro source code.
auto module_ = MakeObject<VbaModule>();
module_->set_Name(u"Aspose.Module");
module_->set_SourceCode(u"New source code");
// Add the module to the VBA project.
doc->get_VbaProject()->get_Modules()->Add(module_);
doc->Save(ArtifactsDir + u"VbaProject.CreateVBAMacros.docm");
Enumerator
DocumentModule 

A type of VBA project item that specifies a module for embedded macros and programmatic access operations that are associated with a document.

ProceduralModule 

A collection of subroutines and functions.

ClassModule 

A module that contains the definition for a new object. Each instance of a class creates a new object, and procedures that are defined in the module become properties and methods of the object.

DesignerModule 

A VBA module that extends the methods and properties of an ActiveX control that has been registered with the project.

◆ VbaReferenceType

Allows to specify the type of a VbaReference object.

Examples

Shows how to get/remove an element from the VBA reference collection.

void RemoveVbaReference()
{
const String brokenPath = u"X:\\broken.dll";
auto doc = MakeObject<Document>(MyDir + u"VBA project.docm");
SharedPtr<VbaReferenceCollection> references = doc->get_VbaProject()->get_References();
ASSERT_EQ(5, references->get_Count());
for (int i = references->get_Count() - 1; i >= 0; i--)
{
SharedPtr<VbaReference> reference = doc->get_VbaProject()->get_References()->idx_get(i);
String path = GetLibIdPath(reference);
if (path == brokenPath)
{
references->RemoveAt(i);
}
}
ASSERT_EQ(4, references->get_Count());
references->Remove(references->idx_get(1));
ASSERT_EQ(3, references->get_Count());
doc->Save(ArtifactsDir + u"VbaProject.RemoveVbaReference.docm");
}
static String GetLibIdPath(SharedPtr<VbaReference> reference)
{
switch (reference->get_Type())
{
return GetLibIdReferencePath(reference->get_LibId());
return GetLibIdProjectPath(reference->get_LibId());
default:
}
}
static String GetLibIdReferencePath(String libIdReference)
{
if (libIdReference != nullptr)
{
ArrayPtr<String> refParts = libIdReference.Split(MakeArray<char16_t>({u'#'}));
if (refParts->get_Length() > 3)
{
return refParts[3];
}
}
return u"";
}
static String GetLibIdProjectPath(String libIdProject)
{
return libIdProject != nullptr ? libIdProject.Substring(3) : u"";
}
Enumerator
Registered 

Specifies an Automation type library reference type.

Project 

Specified an external VBA project reference type.

Original 

Specifies an original Automation type library reference type.

Control 

Specifies a twiddled type library reference type.