使用公式中预定义单元格的文件path

我认为这应该是非常简单的,但我没有运气能够做到这一点或在互联网上寻找它。 显然,我错过了一些非常明显的东西。

我有一个单元格,让我们说A1,它包含以下文件path:

'C:\[Required file path]Sheetname' 

现在我想用这个在单元格B1中创build一个公式,让我们说:

 =Trim('C:\[Required file path]Sheetname'!B26) 

由于这个链接将被dynamic决定,我想能够做到这样的事情:

 =Trim(A1!B26) 

A1 =我需要的文件path。 但是这不起作用。

希望我能够解释这个问题。 感谢预期!

如果您的第二个工作簿(path为'C:\[Required file path]Sheetname'已打开 (但在这种情况下,您不需要使用工作簿的完整path,仅使用WB名称就足够了),则可以使用INDIRECT公式(如果您的A1包含''C:\[Required file path]Sheetname' ):

 =TRIM(INDIRECT(A1 & "!" & CELL("address",B26))) 

但是,如果您的第二个工作簿已closures ,我发现的方法是将用户定义的函数添加到您的第一个工作簿并使用它:

 =TRIM(getValue(A1 & "!" & CELL("address",B26))) 

getValue定义为:

 Function getValue(formulaString As String) Application.Volatile Dim app As Excel.Application Dim wb As Workbook 'set default falue to #REF..if we'd get normal value - we'll change getValue to it' getValue = CVErr(xlErrRef) 'if second WB is open - we can easily evaluate formula and exit function' getValue = Evaluate(formulaString) If Not IsError(getValue) Then Exit Function End If 'if we appear here - second WB is closed...' On Error GoTo ErrHandler Set app = New Excel.Application Set wb = app.Workbooks.Add With wb.Sheets(1).Range("A1") .Formula = "=" & formulaString app.Calculate getValue = .Value End With ErrHandler: If Not wb Is Nothing Then wb.Close False If Not app Is Nothing Then app.Quit Set app = Nothing Set wb = Nothing End Function 

尝试:

 =TRIM([A1]Sheet1!B26) 

其中A1拥有像C:\ Users \ User \ Desktop \ Test.xlsx这样的引用。

它可能会提示您使用文件浏览器 – 只需select您要引用的文档(例如Test.xlsx)