VBA Naming Conventions Procedure NamesName them after what they're doing, using a verb. If accurately naming a procedure is not possible, likely the procedure is doing too many things and needs to be broken down into smaller, more specialized procedures.
To call a Sub procedure from another procedure, type the name of the procedure and include values for any required arguments. The Call statement is not required, but if you use it, you must enclose any arguments in parentheses.
Is there any way to return the name of a function or procedure at runtime?
I'm currently error handling something like this:
Sub foo() Const proc_name as string = "foo" On Error GoTo ErrHandler ' do stuff ExitSub: Exit Sub ErrHandler: ErrModule.ShowMessageBox "ModuleName",proc_name Resume ExitSub End Sub
I recently experienced one of my constants lying to me after I updated a function name, but not the constant value. I want to return the name of the procedure to my error handler.
I know that I will have to interact with the VBIDE.CodeModule
object to find it. I've done a little bit of meta-programming with the Microsoft Visual Basic for Applications Extensibility library, but I've not had any success with doing this at runtime. I don't have my previous attempts, and before I dig my heels in to try this again, I want to know if it's even remotely possible.
Things that won't work
Note
vbWatchdog seems to do this by directly accessing the kernel memory via API calls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With