title: How can make user-defined-function with ADO connection
body: <p>Please help me create a user defined function in excel vba
  example</p>
  
  <pre><code>Function GetTheValue(wbPath, wbName, wsName, cellRef)
      Dim cnn As ADODB.Connection
      Dim rst As ADODB.Recordset
      Dim tmp As Range
      Set cnn = New ADODB.Connection
      Set rst = New ADODB.Recordset
      cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" &amp; _
        "Data Source=" &amp; wbPath &amp; wbName &amp; ";" &amp; _
        "Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
      rst.Open "SELECT * FROM [" &amp; wsName &amp; "$" &amp; cellRef &amp; "]", cnn
      Set tmp = Range("L5")
      tmp.CopyFromRecordset rst
      MsgBox tmp.Value
      GetTheValue = tmp.Value
      rst.Close
      cnn.Close
      Set rst = Nothing
      Set cnn = Nothing
  End Function
  </code></pre>
  
  <p>I tryed to use this in cell by signing formula</p>
  
  <pre><code>=GetThaValue("D:\";"test.xls";"Sheet1";"B4")
  </code></pre>
  
  <p>and see that the string "tmp.CopyFromRecordset rst" of my code did not work
  Please can you help me resolve this question.
  Thanks a lot</p>