如何获取当前VBA函数返回的工作表和单元格?

Jak*_*ake 7 excel vba excel-vba

是否有任何变量可以提供工作表和单元格来接收自定义VBA函数的结果?

例如,如果A!B1公式=MyCustomFunc()在我的代码中:

public function MyCustomFunc()
    'what can I call here to get the values "A" and "B1"?
end function
Run Code Online (Sandbox Code Playgroud)

Sid*_*out 7

这是你在尝试什么?

Option Explicit

Public Function MyCustomFunc()
    '~~> Judicious use of 'Volatile' is advised.
    '~~> This will be called everytime the sheet is recalculated
    Application.Volatile

    MsgBox Application.Caller.Parent.Name & ", " & Application.Caller.Address
End Function
Run Code Online (Sandbox Code Playgroud)