VbaProjectReferenceCollection

VbaProjectReferenceCollection class

代表 VBA 工程的所有引用。

public class VbaProjectReferenceCollection : CollectionBase<VbaProjectReference>

特性

姓名描述
Capacity { get; set; }
Count { get; }
Item { get; }通过索引获取列表中的引用。
Item { get; set; }

方法

姓名描述
AddControlRefrernce(string, string, string, string)添加对旋转类型库及其扩展类型库的引用。
AddProjectRefrernce(string, string, string)添加对外部 VBA 项目的引用。
AddRegisteredReference(string, string)添加对自动化类型库的引用。
BinarySearch(VbaProjectReference)
BinarySearch(VbaProjectReference, IComparer<VbaProjectReference>)
BinarySearch(int, int, VbaProjectReference, IComparer<VbaProjectReference>)
Clear()
Contains(VbaProjectReference)
Copy(VbaProjectReferenceCollection)从其他 VBA 项目复制引用。
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)

例子


[C#]

//实例化一个工作簿对象
Workbook workbook = new Workbook();
 // 初始化 VBA 项目。
VbaProject vbaProject = workbook.VbaProject;
// 添加vba项目引用
vbaProject.References.AddRegisteredReference("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation");
//保存Excel文件
workbook.Save("book1.xlsm");

 [Visual Basic]

'实例化工作簿对象
Dim workbook As Workbook = New Workbook()
'初始化 VBA 项目。
Dim vbaProject as VbaProject  = workbook.VbaProject
'添加vba项目引用
vbaProject.References.AddRegisteredReference("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation")
'保存 Excel 文件
workbook.Save("book1.xlsm")

也可以看看