vbams-wordearly-binding

Access Dictionary Data Type from Word


I need to access Dictionary data type from Microsoft Word. I added the reference to scripting library, but Word has it's own Dictionary data type which I can't turn off or put it's priority lower. It confuses with desired Dictionary, so I decided to use this trick:

Sub Routine()
    Dim T
    T = CreateObject("Scripting.Dictionary")

    ' processing...
End Sub

It works, but I think the knowledge is power, and don't like late binding, so please tell me how to access Dictionary data type from Word.


Solution

  • Using the full name of the class Scripting.Dictionary should resolve the ambiguity of which Dictionary class to consider.

    Sub Routine()
        Dim d As Scripting.Dictionary
        Set d = New Scripting.Dictionary
    
        Debug.Print TypeName(d)
    End Sub
    

    In a way this is same as what you are doing while using CreateObject.