用户定义函数的值

Excel 2010 VBA中有一个用户定义的函数。

在单元格A1 ,我调用该函数: =myfunction()并返回值(作为整数)正确显示在A1单元格中。

我关心的是如何从VBA的其他函数中获取A1单元格的值。 我希望MyOtherFunction()获得A1的数量。

单元格A1=MyFunction()

 function MyFunction() as integer ...... MyFunction = 99 End function 

我在A1看到正确的值99

 function MyOtherFunction() dim valor as integer valor = Workbooks("xxx.xlsm").Sheets("yyy").Range("A1").Value End function 

在该函数中,variablesvalor返回0而不是99

 Function MyOtherFunction(Rng As Range) As Whatever '~~> Rest of the code End Function 

在工作表中作为UDF

 =MyOtherFunction(A1) 

在VBA中

 Sub Sample() Dim Ret Ret = MyOtherFunction(ThisWorkbook.Sheets("Sheet1").Range("A1")) End Sub 

当然你可以写:

 Function MyOtherFunction() MyOtherFunction = Range("A1").Value End Function 

还是我错过了这一点?