VBA 有字典结构吗? [英] Does VBA have Dictionary Structure?

查看:33
本文介绍了VBA 有字典结构吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VBA 有字典结构吗?像 key<>value 数组?

Does VBA have dictionary structure? Like key<>value array?

推荐答案

是.

设置对 MS 脚本运行时的引用(Microsoft 脚本运行时").根据@regjo 的评论,转到工具"->参考"并勾选Microsoft Scripting Runtime"框.

Set a reference to MS Scripting runtime ('Microsoft Scripting Runtime'). As per @regjo's comment, go to Tools->References and tick the box for 'Microsoft Scripting Runtime'.

使用以下代码创建字典实例:

Create a dictionary instance using the code below:

Set dict = CreateObject("Scripting.Dictionary")

Dim dict As New Scripting.Dictionary 

使用示例:

If Not dict.Exists(key) Then 
    dict.Add key, value
End If 

使用完字典后不要忘记将字典设置为Nothing.

Don't forget to set the dictionary to Nothing when you have finished using it.

Set dict = Nothing 

这篇关于VBA 有字典结构吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆