title: For the Application.Run method, what is "a Range object indicating where the function is"?
body: <p>What does it mean that a <strong>Range</strong> object can be a parameter of the <a href="https://docs.microsoft.com/en-us/office/vba/api/excel.application.run" rel="nofollow noreferrer">Application.Run Method (Excel)</a>?</p>
  
  <p>The documentation says the first parameter is "the macro to run. This can be either a string with the macro name, a <strong>Range</strong> object indicating where the function is, or a register ID for a registered DLL (XLL) function. If a string is used, the string will be evaluated in the context of the active sheet."</p>
  
  <p>Does it mean a range with a function name or with code? None of my tests work:</p>
  
  <pre><code>Public Function TestFunctionA()
      MsgBox "It works!"
  End Function
  
  Sub FirstTestOfRunFromRange()
  'Function name in a cell
      Dim rngA As Range
      Set rngA = ActiveSheet.Range("A1")
      rngA = "TestFunctionA"
      Application.Run "TestFunctionA"
      Application.Run rngA
  End Sub
  
  Sub SecondTestOfRunFromRange()
  'Function code in a cell
      Dim rngA As Range
      Set rngA = ActiveSheet.Range("A1")
      rngA = "Public Function TestFunctionB()" &amp; _
          vbCrLf &amp; "MsgBox ""It works!""" &amp; _
          vbCrLf &amp; "End Function"
      Application.Run rngA
  End Sub
  
  Sub ThirdTestOfRunFromRange()
  'Function code as one line per cell
      Dim rngA As Range
      Set rngA = ActiveSheet.Range("A1")
      rngA.Offset(0, 0) = "Public Function TestFunctionB()"
      rngA.Offset(1, 0) = "MsgBox ""It works!"""
      rngA.Offset(2, 0) = "End Function"
      Set rngA = rngA.CurrentRegion
      Application.Run rngA
  End Sub
  
  Sub FourthTestOfRunFromRange()
  'Function code as one line in one cell
      Dim rngA As Range
      Set rngA = ActiveSheet.Range("A1")
      rngA = "Public Function TestFunctionB(): MsgBox ""It works!"": End Function"
      Application.Run rngA
  End Sub
  
  Sub FifthTestOfRunFromRange()
  'Code step in a cell
      Dim rngA As Range
      Set rngA = ActiveSheet.Range("A1")
      rngA = "MsgBox ""It works!"""
      Application.Run rngA
  End Sub
  </code></pre>