Excel 2003 VBA ..编写arraylist

excel 2003 vba.. writing arraylist

我试图在Visual Basic Excel 2003中像Java中那样创建Class的ArrayList

爪哇

1
2
3
4
List<Employee> employees = new ArrayList<Employee>();
Employee employee = new Employee();
employee.setName("tom");
employees.add(employee);

VB

1
2
3
4
5
Dim resultList As New Collection    
Dim Manager As Employee
Manager.Name ="df"    
resultList.Add ("rr") 'correct
resultList.Add (Manager) 'error

但这会产生以下错误:

only user-define types defined in public object modules can be coerced
to or from a variant or passed to late-bound functions


没有与UDT相关联的类型信息,因此无法将其添加到集合中,因为由于其成员的数量和类型未知,因此无法可靠地与变量进行转换。

您可以将Employee Type替换为Class,或者因为您似乎没有使用键,而已键入数组:arr() as Employee