如何获取当前VBA函数返回的工作表和单元格? [英] How to get worksheet and cell that the current VBA function is returning to?

查看:440
本文介绍了如何获取当前VBA函数返回的工作表和单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在任何地方都有变量可以提供工作表和单元格,这些变量可以接收自定义VBA函数的结果吗?

Is there a variable anywhere that gives the worksheet and cell that will recieve the result of a custom VBA function?

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

For example, if in A!B1 the formula is =MyCustomFunc() in my code:

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

推荐答案

这是您要尝试的吗?

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

这篇关于如何获取当前VBA函数返回的工作表和单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆