Class VbaProjectReferenceCollection

VbaProjectReferenceCollection class

Represents all references of VBA project.

public class VbaProjectReferenceCollection : CollectionBase<VbaProjectReference>

Properties

NameDescription
Capacity { get; set; }
Count { get; }
Item { get; }Get the reference in the list by the index.
Item { get; set; }

Methods

NameDescription
AddControlRefrernce(string, string, string, string)Add a reference to a twiddled type library and its extended type library.
AddProjectRefrernce(string, string, string)Adds a reference to an external VBA project.
AddRegisteredReference(string, string)Add a reference to an Automation type library.
BinarySearch(VbaProjectReference)
BinarySearch(VbaProjectReference, IComparer<VbaProjectReference>)
BinarySearch(int, int, VbaProjectReference, IComparer<VbaProjectReference>)
Clear()
Contains(VbaProjectReference)
Copy(VbaProjectReferenceCollection)Copies references from other VBA project.
CopyTo(VbaProjectReference[])
CopyTo(VbaProjectReference[], int)
CopyTo(int, VbaProjectReference[], int, int)
Exists(Predicate<VbaProjectReference>)
Find(Predicate<VbaProjectReference>)
FindAll(Predicate<VbaProjectReference>)
FindIndex(Predicate<VbaProjectReference>)
FindIndex(int, Predicate<VbaProjectReference>)
FindIndex(int, int, Predicate<VbaProjectReference>)
FindLast(Predicate<VbaProjectReference>)
FindLastIndex(Predicate<VbaProjectReference>)
FindLastIndex(int, Predicate<VbaProjectReference>)
FindLastIndex(int, int, Predicate<VbaProjectReference>)
GetEnumerator()
IndexOf(VbaProjectReference)
IndexOf(VbaProjectReference, int)
IndexOf(VbaProjectReference, int, int)
LastIndexOf(VbaProjectReference)
LastIndexOf(VbaProjectReference, int)
LastIndexOf(VbaProjectReference, int, int)
RemoveAt(int)

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.Vba;
    using System;

    public class VbaProjectReferenceCollectionDemo
    {
        public static void VbaProjectReferenceCollectionExample()
        {
            // Instantiating a Workbook object
            Workbook workbook = new Workbook();
            
            // Init VBA project
            VbaProject vbaProject = workbook.VbaProject;
            
            // Add VBA project reference
            vbaProject.References.AddRegisteredReference("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation");
            
            // Add another VBA project reference
            vbaProject.References.AddControlRefrernce("MSForms", "*\\G{0D452EE1-E08F-101A-852E-02608C4D0BB4}#2.0#0#C:\\Windows\\system32\\FM20.DLL#Microsoft Forms 2.0 Object Library", "twiddledLibid", "extendedLibid");
            
            // Add project reference
            vbaProject.References.AddProjectRefrernce("MyProject", "absoluteLibid", "relativeLibid");
            
            // Accessing the references collection
            VbaProjectReferenceCollection references = vbaProject.References;
            
            // Displaying the count of references
            Console.WriteLine("Total References: " + references.Count);
            
            // Accessing a specific reference
            VbaProjectReference reference = references[0];
            Console.WriteLine("First Reference Name: " + reference.Name);
            
            // Copying references from another collection (assuming anotherVbaProjectReferences is another VbaProjectReferenceCollection)
            // VbaProjectReferenceCollection anotherVbaProjectReferences = ...;
            // references.Copy(anotherVbaProjectReferences);
            
            // Saving the Excel file
            workbook.Save("VbaProjectReferenceCollectionExample.xlsm");
        }
    }
}

See Also