Excel VBA 等效于 ADDRESS 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41864274/
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
Excel VBA equivalent of ADDRESS function
提问by mastersom
I want to write this function in vba so that it gives me the cell id.
我想在 vba 中编写这个函数,以便它给我单元格 id。
=ADDRESS(1,2,4,TRUE,"Sheet1")
=ADDRESS(1,2,4,TRUE,"Sheet1")
Does anyone know the VBA syntax for that? Thanks in advance.
有谁知道 VBA 语法吗?提前致谢。
回答by YowE3K
The normal way to do a similar thing in VBA would be either
在 VBA 中做类似事情的正常方法是
Worksheets("Sheet1").Cells(1, 2).Address(RowAbsolute:=False, _
ColumnAbsolute:=False, _
External:=True)
which would return [TestWorkbook.xlsm]Sheet1!B1
or
哪个会返回[TestWorkbook.xlsm]Sheet1!B1
或
Worksheets("Sheet1").Cells(1, 2).Address(RowAbsolute:=False, _
ColumnAbsolute:=False, _
External:=False)
which would just return B1
.
这只会返回B1
。
There isn't a simple way of showing the worksheet name and cell, without also including the workbook name. A possible way would be
在不包含工作簿名称的情况下,没有一种简单的方法可以显示工作表名称和单元格。一种可能的方法是
"'" & Worksheets("Sheet1").Name & "'!" & Worksheets("Sheet1").Cells(1, 2).Address(RowAbsolute:=False, _
ColumnAbsolute:=False, _
External:=False)
(Obviously, if you use Worksheets("Sheet1").Name
then you may as well just use "Sheet1"
, but I wrote it that way so that you could use a variable instead of a hardcoded value. Edit: On rereading that last sentence, I realise how stupid it is - Worksheets(mySheetName).Name
is the same as mySheetName
, so just use "'" & mySheetName & "'!" & ...
)
(显然,如果你使用Worksheets("Sheet1").Name
then 你也可以只使用"Sheet1"
,但我是这样写的,这样你就可以使用变量而不是硬编码值。编辑:在重读最后一句话时,我意识到它是多么愚蠢 -Worksheets(mySheetName).Name
是相同mySheetName
,所以只需使用"'" & mySheetName & "'!" & ...
)