Gleb
Gleb

Reputation: 1432

Debug VBA macros

I have a excel file with macros. It's used like template for our program. Program opens this file, call macros and put data there as parametrs. The question is how can I debug this macros when it's called from the app? For example, in Visual Studio I can use "Attach to process", maybe there is something like this in VBA?

Upvotes: 0

Views: 574

Answers (1)

Kusha Tavakoli
Kusha Tavakoli

Reputation: 181

I have a few different ways to perform debugging in Excel, and none of them are perfect or very sophisticated.

  1. Use debug.print throughout your code to print to the Immediate window to see how the program is executing. This is useful in two scenarios - if you want to see generally how far along your program executed, or where it is in the process of executing, or alternatively, you can go in and add more detail using debug.print if your program is getting snagged somewhere specifically, and you want to see what is happening as the program is executing.
  2. Create an array, enter log information into the array as the program executes, and print the array at the completion of the program execution. This is imperfect because it is not really useful in conditions where the program execution does not complete successfully, but it is useful in scenarios where you want to get some statistics about how the program ran as part of an autopsy.
  3. Add Code Breaks in to the program so that you can see how the program is executing as it is run. Use the Immediate window to check on the values of variables in the program.

Again, none of these are perfect.

Upvotes: 1

Related Questions