我有以下VBA代码(后期绑定):
Dim myList As Object
Set myList = CreateObject("System.Collections.SortedList")
我想替换它(早期绑定):
Dim myList As New SortedList
有没有人成功过这个?我想必须启用引用。但那个参考的名称是什么?
答案 0 :(得分:1)
可能*最简单的方法是在开放时添加它:
Private Sub Workbook_Open()
With ThisWorkbook.VBProject.References
.AddFromFile "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\mscorlib.tlb"
'.AddFromguid "{BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}", 2, 4
End With
End Sub
这会将mscorlib.dll
添加到引用:
然后:
Public Sub TestMe()
Dim myList As SortedList
Dim myList2 As New ArrayList ' as a bonus!
End Sub
来自http://www.snb-vba.eu/VBA_Sortedlist_en.html
\WINDOWS\Microsoft.NET\Framework\v4.0.30319\mscorlib.tlb
或类似目录中找到该库