vba 如何获取字符串范围的地址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43352098/
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 the address of a range to a string
提问by Cy Bu
I have a VBA code that gives an address to an excel range that is active and selected. I am trying to get it as a string.
我有一个 VBA 代码,它为活动和选定的 excel 范围提供地址。我正在尝试将其作为字符串获取。
Sub getRange()
Dim atcSheet As Worksheet
Dim selRange As Range
Dim myRange As String
Set actSheet = ActiveSheet
Set selRange = Selection
MsgBox (selRange.Address)
myRange = selRange.Address(RowAbsolute, ColumnAbsolute)
MsgBox (myRange)
end sub
When running this (after having selected a few cells making a range), MsgBox returns the address, but i could not make it in a variable as a string.
运行它时(在选择了几个单元格形成一个范围之后),MsgBox 返回地址,但我无法将它作为字符串放在变量中。
回答by Subodh Tiwari sktneer
If your intention is to get the absolute reference of the range into an string variable, this will do
如果您的目的是将范围的绝对引用放入字符串变量中,则可以这样做
myRange = selRange.Address
Address(True, True) is by default.
Address(True, True) 是默认的。
回答by Shai Rado
Use:
用:
myRange = selRange.Address(True, True)
' for debug
MsgBox myRange