title: Excel VBA - pass name of class method to another subroutine to call the method
body: <p>I have an add-in file named "MyFunctions.xlam".  This contains several helper functions, including custom solvers, etc.  </p>
  
  <p>In MyFunctions, I have a Class named "ChemicalRelease".  This class has a property of massRate and a public function named "affectedArea".  The "affectedArea" method goes thru several calculations and method calls to determine the affected area size of a chemical release, based on a provided mass rate and several other factors.  I have a target affected area size, and am looking to use a solver to back calculate an appropriate mass rate that would result in the target affected area size.</p>
  
  <p>Inside of the ChemicalRelease Class Module, a method named "varyMassRateForTargArea" attempts to solve for massRate using the secant solver, targeting a specified affected area:</p>
  
  <p>massRate = solverSecant(massRate, "ChemicalRelease.affectedArea", targArea, 0, False)</p>
  
  <p>"solverSecant" is in "Module1" of "MyFunctions", and is meant to be generic enough to be used by any class method.</p>
  
  <p>Here is some code for "solverSecant":</p>
  
  <pre><code>Function solverSecant(ByRef varyingProperty, methodToRun, Optional yTarget = 0#, Optional dx = 0, Optional dDebug As Boolean = False)
  
  x0 = varyingProperty
  
  If dx &lt;= 0 Then dx = x0 / 1000
  
  maxIter = 1000
  
  currIter = 0
  
  xTol = dx / 10
  
  x1 = x0 + dx
  
  x0 = varyingProperty
  y0 = Application.Run(methodToRun) - yTarget
  ...
  </code></pre>
  
  <p>the "solverSecant" method needs to do the following:</p>
  
  <ol>
  <li>update the property value for massRate in the instantiated ChemicalRelease object.</li>
  <li>run the object's "affectedArea" method with the updated property value from step #1.</li>
  <li>do the rest of the solver algorithm, but that part should work ok, given that the other two requirements are met.</li>
  </ol>
  
  <p>My questions are:</p>
  
  <ol>
  <li><p>Once an instance of "ChemicalRelease" is initialized, and the "varyMassRateForTargArea" method is called, is it possible to pass the reference to the instantiated "ChemicalRelease" object from "varyMassRateForTargArea" to "solverSecant" in "Module1"?  This would be equivalent of sending "self" as an argument in every other language I can think of.</p></li>
  <li><p>Is there some way to run the "ChemicalRelease.affectedArea" method from "Module1"?  I can't seem to get it to work with "Application.Run", but I may not have the syntax correct.</p></li>
  </ol>
  
  <p>Thank you for your help.  I understand that I can have the solver as part of a method in the class object, but I'd rather develop a solver in the "MyFunctions" that can apply it to any other method/property of other classes.</p>