是否有一個變量可以讓工作表和單元格能夠接收自定義VBA函數的結果?如何獲取當前VBA函數返回的工作表和單元格?
例如,如果在A!B1
公式是在我的代碼=MyCustomFunc()
:
public function MyCustomFunc()
'what can I call here to get the values "A" and "B1"?
end function
是否有一個變量可以讓工作表和單元格能夠接收自定義VBA函數的結果?如何獲取當前VBA函數返回的工作表和單元格?
例如,如果在A!B1
公式是在我的代碼=MyCustomFunc()
:
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
是的,確實如此。用純英語來描述這個真的很難。謝謝! – Jake 2012-04-27 06:21:31
ActiveSheet.Name
會給你的工作表名稱。 ActiveCell.Row
會給你一個行號,ActiveCell.Column
會給你列的字母。然後你可以將它們組合起來得到單元地址。
謝謝,但Activecell只給出活動單元格。我不要那個。我想要獲取函數結果的單元格和工作表。 – Jake 2012-04-27 05:34:57
想要Application.ThisCell
。
這將返回當前正在計算的單元格。
你究竟在做什麼? – 2012-04-27 05:43:12