vba 如何获取在Excel工作表中调用VBA函数的单元格地址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2259035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get address of cell which calls a VBA Functions in a Excel sheet
提问by Nimo
Is there a function to get the address of a cell which call a VBA function ?
是否有获取调用 VBA 函数的单元格地址的函数?
I used "Application.ActiveCell.Address" , but found that this method is not a correct way to get the address of calling cell.
我使用了 "Application.ActiveCell.Address" ,但发现这种方法不是获取调用单元地址的正确方法。
e.g: If we have excel sheet with saved VBA functions, Once you reopen the sheet, the above method will not work.
例如:如果我们有保存了 VBA 函数的 Excel 工作表,一旦您重新打开工作表,上述方法将不起作用。
please help
请帮忙
nimo
尼莫
回答by Fionnuala
You can use Application.Caller, but you would probably be best to pass the cell to the function.
您可以使用 Application.Caller,但最好将单元格传递给函数。
With Application.Caller
CallerRows = .Rows.Count
CallerCols = .Columns.Count
CallerAddr = .Address
End With
See: http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
请参阅:http: //www.cpearson.com/excel/WritingFunctionsInVBA.aspx
To pass the cell:
要传递单元格:
=SomeFunction(A1)
Where the code has:
代码有:
SomeFunction(r)

