title: How to get the procedure or function name at runtime?
body: <p>Is there <em>any</em> way to return the name of a function or procedure <em>at runtime</em>? </p>
  
  <p>I'm currently error handling something like this:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <p>I know that I will have to interact with the <code>VBIDE.CodeModule</code> 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.</p>
  
  <p><strong>Things that won't work</strong></p>
  
  <ol>
  <li>Using some built in VBA Library to access the call stack. It doesn't exist. </li>
  <li>Implementing my own call stack by pushing and popping procedure names from an array as I enter and exit each one. This still requires that I pass the proc name somewhere else as a string. </li>
  <li>A third party tool like <a href="http://www.everythingaccess.com/vbwatchdog.htm" rel="noreferrer">vbWatchDog</a>. This <em>does</em> work, but I can't use a third party tool for this project. </li>
  </ol>
  
  <p><strong>Note</strong></p>
  
  <p>vbWatchdog seems to do this by directly accessing the kernel memory via API calls.</p>