WoodenKitty
WoodenKitty

Reputation: 6529

Excel VBA. How to check if a sub is called anywhere in a Workbook (eg what buttons)

How do you check where an Excel VBA Sub is called from? It's easy enough to hit CTRL+F to find where in the code it may be called, but suppose there's an obscure hidden button that calls the Sub. How would you know?

Upvotes: 1

Views: 4485

Answers (2)

Kazimierz Jawor
Kazimierz Jawor

Reputation: 19067

Even if you use CTRL+F in IDE you won't find the situation when standard form button is set to run that macro on action. Moreover, any of shape within your Workbook could have on action set to your sub. You would then need to check each of it. But if you need to check such situation during compilation you could use something like:

Debug.Print Application.Caller

If your sub would be started from standard button then you get information Button 1 or shape name if was start from any other shape. Important! You would require error handling procedure if you use that check syntax for situation when your sub is called from other sub.

For other check Santosh idea, yours, and finally you could write some code which search all modules to find your sub and list it.

Upvotes: 0

Santosh
Santosh

Reputation: 12353

Kindly install the addin mztools. It has an option Procedure Callers which list down all the places from where the procedure is called.

The below image shows all the procedure callers for procedure a. enter image description here

Upvotes: 2

Related Questions