Aspose::Words::Vba::VbaReference::get_LibId method
Contents
[
Hide
]VbaReference::get_LibId method
Gets a string value containing the identifier of an Automation type library.
virtual System::String Aspose::Words::Vba::VbaReference::get_LibId() const =0
Remarks
Depending on reference type, the value of this property can be:
- a LibidReference specified at 2.1.1.8 LibidReference of [MS-OVBA]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-ovba/3737ef6e-d819-4186-a5f2-6e258ddf66a5
- a ProjectReference specified at 2.1.1.12 ProjectReference of [MS-OVBA]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-ovba/9a45ac1a-f1ff-4ebd-958e-537701aa8131
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())
{
case VbaReferenceType::Registered:
case VbaReferenceType::Original:
case VbaReferenceType::Control:
return GetLibIdReferencePath(reference->get_LibId());
case VbaReferenceType::Project:
return GetLibIdProjectPath(reference->get_LibId());
default:
throw System::ArgumentOutOfRangeException();
}
}
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"";
}
See Also
- Class VbaReference
- Namespace Aspose::Words::Vba
- Library Aspose.Words for C++