从VBA中的集合中检索数据

我试图检索存储在VBA集合中的数据。 我不太确定如何检索数据。 它给我一个types不匹配的错误。

我的代码如下所示:

Set col = New Collection col.Add BGN_arr, "BGN" col.Add CBBT_arr, "CBBT" Dim curr_arr() As Variant Set curr_arr = col("BGN") 

也试过这个:

 Set curr_arr = col.Item ("BGN") 

需要一些指导。

你有两个问题,我看到:

  1. 你已经设置了curr_arr() As Variant – 这不应该是一个数组。
  2. 你正在使用Set方法会导致一个问题。

这个代码应该工作:

 Set col = New Collection col.Add BGN_arr, "BGN" col.Add CBBT_arr, "CBBT" Dim curr_arr As Variant curr_arr = col.Item ("BGN")