0

I am getting a runtime error in VBA. I have no error-handling and don't really wish to employ this unless necessary. When I get the run-time error window option to End, Debug or Help, I press Debug. The code editor window opens but in my case it highlights in yellow a line "Load Frm" - which is obviously tells me the error has occurred somewhere in the process of loading the form, but I then have to F8 throughout the whole series of routines which are called until I reach the line that has actually caused the error. This can take a long time! Am I missing something?

5
  • 2
    Sounds like typical debugging to me. You could add error handling, logging, or other techniques to narrow it down some. Commented Sep 25, 2020 at 15:13
  • What is the whole error message? Commented Sep 25, 2020 at 15:20
  • Thanks Brian. But I don't understand why the default error handling doesn't actually highlight and position the offending line, instead the load statement (which is several 100 lines of code short of the actual error) Commented Sep 25, 2020 at 15:37
  • Thanks dwirony, the error itself is immaterial to the question - I could reproduce this with many different type of errors. Commented Sep 25, 2020 at 15:38
  • 3
    Break in class module. Commented Sep 25, 2020 at 16:07

2 Answers 2

3

I use Google Translator, so there may be some inaccuracies, but I think you understand.

  • In the "Tools" menu of the VBA editor select "Options"
  • Select the "General" tab
  • In the "Error detection" frame select "Abort in class module" and confirm with OK.
Sign up to request clarification or add additional context in comments.

1 Comment

Error detection -> Error trapping / Abort in class module -> Break in Class module
0

In order to quickly find the line with the actual error you can use the following hot keys:

Shift+F8 when pressed on a line containing a procedure will run the whole procedure (even if it contains several lines inside) and then stop at the next line. If you have stepped inside a procedure you can press Ctrl+Shift+F8 to run everything inside it and go to the next line of the outer procedure. In other words if Sub A at line 5 calls Sub B and you stepped into Sub B, pressing Ctrl+Shift+F8 will run everything in Sub B and return to line 6 of Sub A.

Don't forget about breakpoints, they're very useful.

3 Comments

Yes, all those facilities I am aware of - thank you. But the same question persists - why is the program highlighting the wrong line, the kind-of top level line?
VBA can't do everything. It ends up calling internal libraries (Through COM, unmanaged code and so on). When there is an error in a component outside of VBA's reach you'll get an error in the top-level line. At least that's my experience working with outside libraries. Errors tend to get messy when you call external stuff.
I'm not actually calling external stuff or using outside libraries, it's all VBA

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.