【VBA】Dictionaryの存在確認|DicExists
記事更新日:2022-12-03

Dictionaryの存在確認
Dictionaryに要素が存在していればTrueを返す
Option Private Module
Option Explicit
Public Function DicExists( _
ByVal dic As Object, _
ByVal key As String) As Boolean
DicExists = False
If dic.exists(key) Then DicExists = True
End Function
呼び出し方
Private Sub Test()
Dim i As Long
Dim dic As Object: Set dic = SetDIC
For i = 1 To 100
If Not DicExists(dic, xx) Then 'キー(xx)がdicに存在しなければ
Set dic = AddDicKeyValue(dic, xx, yy) 'キー(xx)と要素(yy)を追加する
'なにかの処理
End If
Next i
End Sub
関連記事
2022-12-03
編集後記:
この記事の内容がベストではないかもしれません。