我试图在不打开源文件的情况下从另一个工作簿中检索单元格值。当我使用实际的单元格地址时,下面将返回“SourceRange”中的值。但是,我想修改下面的代码来引用单元格名称而不是单元格地址,因为可能会添加行。因此,如果源工作簿中的单元名称被命名为“Total”,那么我有办法检索该值吗?
Sub OpenFiles()
Dim Folder_YR As String
Dim Folder_MO As String
Dim Path As String
Dim File As String
Dim SourceSheet As String
Dim SourceRange As String
Folder_YR = Sheets("Inputs").Range("B5").Value
Folder_MO = Sheets("Inputs").Range("B9").Value
FN = Sheets("Inputs").Range("B10").Value
Path = "G:\PMT ACTIVITY\" & Folder_YR & "\" & Folder_MO & "\"
File = FN
SourceSheet = "Summary"
SourceRange = Range("C1").Address(1, 1, xlR1C1)
Ref = "'" & Path & "[" & File & "]" & SourceSheet & "'!" & SourceRange
Sheets("Model").Range("C18").Formula = ExecuteExcel4Macro(Ref)
End Sub
答案 0 :(得分:-1)
格式类似于'C:\Book1.xlsx'!Total
[Model!C18].Formula = "='" & Path & File & "'!Total"