VBA_Excel_教程:字典类型
Posted Andy 胡
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VBA_Excel_教程:字典类型相关的知识,希望对你有一定的参考价值。
VBA中的字典类型需要添加Microsoft Scripting Runtime引用,在Tools菜单下添加
Sub testDic() Dim strV As String Dim key As String key = "name" Dim value As String value = "关羽" Dim dic As Object Set dic = CreateObject("Scripting.Dictionary") ‘增 If dic.exists(key) = False Then dic.Add key, value End If Call read(dic) ‘删1 dic.Remove (key) Call read(dic) ‘删2:移除全部内容 ‘ dic.RemoveAll Call read(dic) End Sub Sub read(dic As Object) ‘遍历读取 For Each k In dic strV = dic.Item(k) Debug.Print strV Next End Sub
以上是关于VBA_Excel_教程:字典类型的主要内容,如果未能解决你的问题,请参考以下文章