【问题标题】:VBA Return Cell Value from a Named Cell in a Closed WorkbookVBA 从已关闭工作簿中的命名单元格返回单元格值
【发布时间】:2016-07-07 07:45:43
【问题描述】:

我试图在不打开源文件的情况下从另一个工作簿中检索单元格值。当我使用实际的单元格地址时,下面将返回来自“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

【问题讨论】:

标签: vba excel-2010


【解决方案1】:

格式类似于'C:\Book1.xlsx'!Total

https://www.ablebits.com/office-addins-blog/2015/12/08/excel-reference-another-sheet-workbook/#reference-to-defined-name-another-workbook

[Model!C18].Formula = "='" & Path & File & "'!Total"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多