我使用此函数从已关闭的工作簿中检索值。在这段代码的第8行中,我不明白为什么要使用"A1“。这整个第8行到底发生了什么?我也被xlR1C1的论点搞糊涂了。
Private Function GetValue(path, file, sheet, ref)
Dim arg As String
If Right(path, 1) <> "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(ref).Range("A1").Address(, , xlR1C1)
GetValue = ExecuteExcel4Macro(arg)
End Function发布于 2015-01-08 04:44:33
Range().Range() Documentation here
当应用于
Range对象时,该属性相对于Range对象。例如,如果所选内容是单元格C3,则Selection.Range("B1")将返回单元格D3,因为它相对于Selection属性返回的Range对象。另一方面,代码ActiveSheet.Range("B1")总是返回单元格B1。
代码使用第二个Range("A1")来确保如果您的ref区域大于一个单元格,则它只返回该区域的左上角单元格。另外,您的另一个名为ExecuteExcel4Macro()的Sub似乎需要一个R1C1类型的单元格引用,因此地址将被转换为该类型,以便将arg字符串传递给Sub。
https://stackoverflow.com/questions/27827384
复制相似问题