Compile throws a “User-defined type not defined” error but does not go to the offending line of code

前端 未结 21 1274
再見小時候
再見小時候 2020-12-14 08:00

Symptoms

This is a symptom specifically when compiling an Excel VBA project. The following error occurs:

User-defined type not defin

21条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 08:28

    For the Scripting.Dictionary type, you can either use late binding (as already pointed out ) with:

    Dim Dict as Object
    Set Dict = CreateObject("Scripting.Dictionary")
    

    Which works, but you don't get the code auto completion. Or you use early binding, but you need to make sure that VBA can find the Scripting.Dictionary type by adding the reference to the Microsoft Scripting Library via VBA-->Tools-->References--> "Microsoft Scripting Runtime". Then you can use:

    Dim Dict as Scripting.Dictionary
    Set Dict = New Scripting.Dictionary
    

    ... and auto completion will work.

提交回复
热议问题