1

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

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

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

细胞A1=MyFunction()

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

我正确地看到99A1.

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

在该函数中,变量valor返回。099

4

2 回答 2

0

当然你可以写:

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

还是我错过了重点?

于 2013-10-17T19:52:00.607 回答
0
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
于 2013-10-17T19:52:23.577 回答