如何在Visual Basic for Applications中使用“类模块”或“模块”?

时间:2011-09-19 04:43:50

标签: excel excel-vba excel-2010 vba

我正在尝试在中创建一个集合,但无法弄清楚如何执行此操作。任何人都可以向我解释这个或者发送给我一些链接吗?

我一直在研究这个相同的“语言问题”几个小​​时。我已经检查过SO,谷歌,MSDN和F1帮助无济于事。

2 个答案:

答案 0 :(得分:3)

基本方法是:

声明一个Collection对象

Dim oCol As Collection

创建对象的实例

Set oCol = New Collection

将内容添加到集合

oCol.Add Item:=1, Key:="Item1IsANumber"
oCol.Add Item:="SomeString", Key:="Item2IsAString"

参阅项目

z = oCol.Item(1)  ' z = 1
z = oCol.Item(2)  ' z = "SomeString"
z = oCol.Item("Item1IsANumber")  ' z = 1
z = oCol.Item("Item2IsAString")  ' z = "SomeString"

CPearson.com是很多事情的好参考vba

这是集合页面的Link

答案 1 :(得分:2)

你能否更明确地了解你想要制作的系列 - 下面是一些更好的课程模块和收藏链接的集合。

课程模块

  1. Walkenbacks colour button class module
  2. Pearson class modules
  3. Peltier,Chart event class module
  4. 词典v集合

    1. Patrick Matthews Using the Dictionary Class in VBA