title: Is it possible to create a function that returns an object?
body: <p>I am working on a macro which will require referencing a large number of named ranges using:</p>
  
  <pre><code>ThisWorkbook.Names("$NAMEDRANGE$").RefersToRange.$METHOD$
  </code></pre>
  
  <p>I thought it might make the code easier to read/work with if I could create a function which I could use as follows:</p>
  
  <pre><code>NamedRange("$NAMEDRANGE$").$METHOD$
  </code></pre>
  
  <p>Without really knowing if it would work, I tried the following:</p>
  
  <pre><code>Function NamedRange(ByVal sName As String) As Object
      return ThisWorkbook.Names(sName).RefersToRange
  
  End Function
  </code></pre>
  
  <p>This won't even compile, producing an</p>
  
  <blockquote>
    <p>Expected: end of statement</p>
  </blockquote>
  
  <p>I think I may need to use a Class Module, but I'm not very familiar with them. Is this possible, or should I just spell out the entire reference on each line?</p>
  
  <hr>
  
  <p>I have been spending too much time in C. This code works perfectly:</p>
  
  <pre><code>Function NamedRange(ByVal sName As String) As Object
     Set NamedRange = ThisWorkbook.Names(sName).RefersToRange
  
  End Function
  </code></pre>
  
  <p>Thanks for the help!</p>