TLDR
Open the module with the problem and press the following keystrokes:
ctrl+home
to go to the top of the module
'
to add a comment in front of Option Explicit
down
to parse all without Option Explicit
and tell VBA that all needs to be recompiled
up
backspace
to uncomment
alt+d
l
to trigger the recompilation of the whole module
The solution described above assumes the modules in the VBA project use Option Explicit
, (which they should, it is very good practice). If your modules do not use it, then, instead of commenting and uncommenting the first line, you can select all the code, cut it and paste it back.
The details
This problem is caused by something going wrong with the incremental compilation.
When a module is edited, VBA compiles only the modified functions, not the whole project. Sometimes things go wrong with the incremental compilation and two things can happen at execution time: phantom breakpoints like the one mentioned here appear or errors about undefined or wrong type variables show up.
The answers that mention modifying one line often help, because they do trigger the compilation of the function containing that line, which in turn may trigger the compilation of other functions or even the entire project. But the problem sometimes pops back up because editing one line only may not trigger the compilation of the whole project.
The answer with the highest number of upvotes may help, but it requires first to reproduce the problem, which sometimes doesn't reproduce on the development machine.
The correct solution is to force the recompilation of the whole project.
I don't think there is an explicit way to do so, but it is possible to force the recompilation of the largest module, one that is used by or uses all modules and classes. There is no command to trigger such recompilation, but by changing one global directive will do the job.
In some cases it may be necessary to repeat the steps in multiple modules.