2017-03-21 156 views
0

我想打电话从VBA Excel的FORECAST.ETS在我访问项目,但它似乎是不管我做什么,我得到这个错误:从Access调用Excel的function.ets VBA

"VBA Error 1004 Invalid number of arguments."

这里是我在做 -

'********************************************** 
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)包装数组,甚至将Arrays设置为Variant。

回答

0

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

+0

是的,它的Forecast_ETS在Excel VBA中,但是它应该给出一个错误函数或过程定义没有找到类似的东西 –

+0

谢谢。我插入了Forecast_ETS,但得到了这个 - “无法获得WorksheetFunction类的Forecast_ETS属性”.. – tomkoel

+0

谢谢!我将名称更改为Forecast_ETS并获取了此名称 - 无法获取WorksheetFunction类的Forecast_ETS属性。这是比“无效的参数数量”更好的错误吗? – tomkoel