【问题标题】:Calling excel's function.ets from Access VBA从 Access VBA 调用 excel 的 function.ets
【发布时间】:2017-03-21 13:19:54
【问题描述】:

我试图在我的访问项目中从 VBA 调用 excel 的 FORECAST.ETS,但似乎无论我做什么我都会收到此错误:

“VBA 错误 1004 参数数量无效。”

这就是我正在做的 -

'**********************************************
Public Sub testFCsof()

Dim testrfXL As Object

Dim testrfNowDate  As Date
Dim testrfempSQLStr As String
Dim testrfempSQLRS As DAO.Recordset

Dim testrfRecNo As Integer

Dim testrfDateARRAY() As Date
Dim testrfPointsARRAY() As Double

Dim testrfFDFCAST As Double
Dim fdtestempID As Long

On Error GoTo Err_testrfNBA

Set todaysDB = CurrentDb()

fdtestempID = 382

testrfFDFCAST = 1000000

testrfempSQLStr = "SELECT NBAFANempPER.eventTime, NBAFANempPER.FDpoints " & _
            "FROM NBAFANempPER WHERE ((NBAFANempPER.empID)= " & fdtestempID & ") ORDER BY NBAFANempPER.eventTime;"

Set testrfempSQLRS = todaysDB.OpenRecordset(testrfempSQLStr, dbOpenDynaset, dbSeeChanges, dbReadOnly)

If Not (testrfempSQLRS.BOF And testrfempSQLRS.EOF) Then 'only do this if we have records

testrfempSQLRS.MoveLast

ReDim testrfDateARRAY(testrfempSQLRS.RecordCount - 1)
ReDim testrfPointsARRAY(testrfempSQLRS.RecordCount - 1)

testrfempSQLRS.MoveFirst

testrfRecNo = 0

Do While Not testrfempSQLRS.EOF

    testrfDateARRAY(testrfRecNo) = CDate(dateHeadFunk(CDate(testrfempSQLRS!eventTime)))
    testrfPointsARRAY(testrfRecNo) = CDbl(testrfempSQLRS!FDpoints)

    testrfRecNo = testrfRecNo + 1

    testrfempSQLRS.MoveNext
Loop

Set testrfXL = CreateObject("Excel.Application")

testrfNowDate = Now()

testrfFDFCAST = testrfXL.WorksheetFunction.Forecast.ets(Arg1:=testrfNowDate, Arg2:=testrfPointsARRAY, Arg3:=testrfDateARRAY, Arg4:=0, Arg5:=1, Arg6:=5)

Set testrfXL = Nothing

End If


Exit_testrfNBA:

Erase testrfPointsARRAY
Erase testrfDateARRAY
testrfNowDate = Empty

testrfempSQLStr = ""

If Not testrfempSQLRS Is Nothing Then
    testrfempSQLRS.Close
    Set testrfempSQLRS = Nothing
End If

Exit Sub


Err_testrfNBA:

    MsgBox "Got a sucky forecast number back.."

 generic.TestODBCErr

Resume Exit_testrfNBA

End Sub
'**********************************************

数组填充得很好,大小相同。
我可以毫无问题地调用其他 Excel 函数。
无法弄清楚问题可能是什么。我已经尝试过使用和不使用“Arg=”标签,使用和不使用最后三个可选参数,尝试使用 Array(myArray) 包装数组,甚至将数组设置为 Variant。

【问题讨论】:

    标签: vba excel ms-access


    【解决方案1】:

    至少在 Excel VBA 中,函数名称是 Forecast_ETS,而不是 Forecast.ETS。

    【讨论】:

    • 是的,它在 excel vba 中的 Forecast_ETS,但它是否应该给出错误函数或过程定义未找到或类似的东西
    • 谢谢。我插入了 Forecast_ETS,但得到了这个 - “无法获取 WorksheetFunction 类的 Forecast_ETS 属性”..
    • 谢谢!我将名称更改为 Forecast_ETS 并得到了这个 - 无法获取 WorksheetFunction 类的 Forecast_ETS 属性。这是比“无效的参数数量”更好的错误吗?
    • 抱歉没有解决。我希望其他人有答案。同时,尽量不要把你的挫败感发泄到试图提供帮助的人身上。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 2012-03-17
    • 2016-02-27
    • 1970-01-01
    相关资源
    最近更新 更多