请帮我在 excel vba 示例中创建一个用户定义的函数
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;" & _
"Data Source=" & wbPath & wbName & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
rst.Open "SELECT * FROM [" & wsName & "$" & cellRef & "]", 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
我试图通过签署公式在单元格中使用它
=GetThaValue("D:\";"test.xls";"Sheet1";"B4")
并看到我的代码的字符串“tmp.CopyFromRecordset rst”不起作用请你帮我解决这个问题。非常感谢