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

前端 未结 21 1267
再見小時候
再見小時候 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:46

    Just letting you all know I had this problem too. Rather than the code, the issue lay with what macro a button was calling. (It had been calling the 'createroutes.createroutes' macro, but I had renamed the 'createroutes' module to 'routes'.) Therefore the problem was fixed by pointing the button to the correct location.

    0 讨论(0)
  • 2020-12-14 08:46

    Late Binding

    This error can occur due to a missing reference. For example when changing from early binding to late binding, by eliminating the reference, some code may remain that references data types specific the the dropped reference.

    Try including the reference to see if the problem disappears.

    Maybe the error is not a compiler error but a linker error, so the specific line is unknown. Shame on Microsoft!

    0 讨论(0)
  • 2020-12-14 08:49

    I don't have an answer as to what is actually wrong or to directly fix it.

    I can report that exporting all the code and forms, then importing them into a fresh workbook fixed it for me. All the work was recovered, and nothing more needed to be done to get back to work. Since that works, it seems clear that it must be a bug in Excel, or whatever it is would still be missing in the new version.

    I do have a possible clue to how this Excel (2007) bug works. It seems to be associated with the removal of a class module (or two). (But not every class module, every time for some reason.) No code was using any part of the removed modules (or the new imported version would not work either). One module had been cut down to nothing but some comments (in hope of removing anything that could be "missing" later) so that there was no code visibly connecting it to any other part of the project. But the error came up shortly after I removed the code module entirely. The error also stopped when the removed (but exported just in case) modules were returned. So for convenience, this project had been packing two unused code modules to avoid this error.

    It appears then, that somehow some element of some departed modules remains in the VBA environment, even if nothing is being used from these (there two in this case) class modules anywhere in the project. Consequently, the debug/compile finds that element, and it is no surprise that something is missing because it is. Since the thing that is missing is nowhere in the project there is nothing to highlight so there is a message only and nothing else happens. That would explain the observed behavior.

    0 讨论(0)
提交回复
热议问题