嗨,我正尝试通过此功能将Excel函数Median加载到MS-ACCESS:
Public Function excel() As Integer
Dim db As DAO.Database
Dim rs As Recordset
Dim i As Long
Dim p, p2 As Double
Dim a(), b()
Dim res As String
Set db = CurrentDb
Set rs = db.OpenRecordset("testovaci")
Dim oExcel As Object
Set oExcel = CreateObject("excel.application")
rs.MoveFirst
p = rs.RecordCount
ReDim a(p)
ReDim b(p)
For i = 0 To p - 1
a(i) = rs.Fields("cislo").Value
rs.MoveNext
'Debug.Print a(i)
Next i
For i = 0 To p - 1
If i = 0 Then
res = a(i)
Else
res = res & ", " & a(i)
End If
Debug.Print res
Next i
excel = oExcel.Worksheetfunction.Median(res)
End Function
如果我在这样的函数中输入参数:
excel = oExcel.Worksheetfunction.Median(1, 2, 3)
然后它起作用,但是如果我尝试传递值res = 1,2,3的字符串,则它不起作用。 您是否知道如何用ms-access数据填充此功能以使其正常工作?
答案 0 :(得分:1)
有两个问题:
将数组传递给函数而不是字符串excel = oExcel.Worksheetfunction.Median(a())
我的整个函数都被声明为整数,但我希望从双Public Function excel() As DOUBLE