VbaReferenceCollection Class

Represents a collection of VbaReference objects.

ExpandedInheritance Hierarchy

SystemObject
  Aspose.Words.VbaVbaReferenceCollection

Namespace:  Aspose.Words.Vba
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 22.1.0

ExpandedSyntax

public sealed class VbaReferenceCollection : IEnumerable<VbaReference>, 
	IEnumerable

The VbaReferenceCollection type exposes the following members.

ExpandedProperties

  NameDescription
Public propertyCode exampleCount
Returns the number of VBA references in the collection.
Public propertyItem
Gets VbaReference object at the specified index.

ExpandedMethods

  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodCode exampleRemove
Removes the first occurrence of a specified VbaReference item from the collection.
Public methodCode exampleRemoveAt
Removes the VbaReference element at the specified index of the the collection.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)

ExpandedExamples

Shows how to get/remove an element from the VBA reference collection.
[Test]
public void RemoveVbaReference()
{
    const string brokenPath = @"X:\broken.dll";
    Document doc = new Document(MyDir + "VBA project.docm");

    VbaReferenceCollection references = doc.VbaProject.References;
    Assert.AreEqual(5 ,references.Count);

    for (int i = references.Count - 1; i >= 0; i--)
    {
        VbaReference reference = doc.VbaProject.References[i];
        string path = GetLibIdPath(reference);

        if (path == brokenPath)
            references.RemoveAt(i);
    }
    Assert.AreEqual(4 ,references.Count);

    references.Remove(references[1]);
    Assert.AreEqual(3 ,references.Count);

    doc.Save(ArtifactsDir + "VbaProject.RemoveVbaReference.docm"); 
}

/// <summary>
/// Returns string representing LibId path of a specified reference. 
/// </summary>
private static string GetLibIdPath(VbaReference reference)
{
    switch (reference.Type)
    {
        case VbaReferenceType.Registered:
        case VbaReferenceType.Original:
        case VbaReferenceType.Control:
            return GetLibIdReferencePath(reference.LibId);
        case VbaReferenceType.Project:
            return GetLibIdProjectPath(reference.LibId);
        default:
            throw new ArgumentOutOfRangeException();
    }
}

/// <summary>
/// Returns path from a specified identifier of an Automation type library.
/// </summary>
private static string GetLibIdReferencePath(string libIdReference)
{
    if (libIdReference != null)
    {
        string[] refParts = libIdReference.Split('#');
        if (refParts.Length > 3)
            return refParts[3];
    }

    return "";
}

/// <summary>
/// Returns path from a specified identifier of an Automation type library.
/// </summary>
private static string GetLibIdProjectPath(string libIdProject)
{
    return libIdProject != null ? libIdProject.Substring(3) : "";
}

ExpandedSee Also