如何将函数的结果返回到Excel中的单元格?

BIB*_*IBD 3 excel vba excel-vba

假设我的Excel工作表附加了一个函数:

Public Function foo(bar As Integer) as integer
    foo = 42
End Function
Run Code Online (Sandbox Code Playgroud)

如何获得foo返回到工作表中单元格的结果?我试过了"=foo(10)",但它给了我的全部是"#NAME?"

我也试过=[filename]!foo(10) and [sheetname]!foo(10)没有改变.

Ste*_*hen 5

请按照此处的说明进行操作,以确保您正确执行所有操作,尤其是放置位置.(Insert->Module)

我可以确认打开VBA编辑器,使用Insert->Module和以下代码:

Function TimesTwo(Value As Integer)
    TimesTwo = Value * 2
End Function
Run Code Online (Sandbox Code Playgroud)

并放在一张放入"=TimesTwo(100)"牢房的床单上200.