简体   繁体   English

Excel - 使用文件名(存储在单元格中)来引用该文件中的值

[英]Excel - using the name of the file (stored in a cell) to reference values from that file

in B1 cell I have a reference to a value stored in some other Excel file:在 B1 单元格中,我引用了存储在其他 Excel 文件中的值:

='C:\\podatki\\Finance\\Sp\\Predloge\\[L2019-1.xlsx]List1'!$A$4

The name of the file is "L2019-1.xlsx".文件名为“L2019-1.xlsx”。

I would like to use A column for list of files: A1 for the first name, A2 for the second, etc...) and I would like to have B column with references to the files in the A column.我想使用 A 列作为文件列表:A1 用于第一个名称,A2 用于第二个,等等...)并且我希望 B 列包含对 A 列中文件的引用。

For instance, if A1 cell is "Xfiles.xlsx" then B1 would be:例如,如果 A1 单元格是“Xfiles.xlsx”,那么 B1 将是:

='C:\\podatki\\Finance\\Sp\\Predloge\\[Xfiles.xlsx]List1'!$A$4

Which formula should I put inside [] part of the path to always get the correct name of the file (from A column)?我应该将哪个公式放入路径的 [] 部分以始终获得文件的正确名称(来自 A 列)?

Thank you.谢谢你。

I assume you still want to get the value from cell A4 in L2019-1.xlsx (and not just the reference string), correct?我假设您仍然想从L2019-1.xlsx单元格A4中获取值(而不仅仅是参考字符串),对吗? In this case, simply building up the reference string based on the file name in A1 will just give you a string, but not the value from A4 in L2019-1.xlsx .在这种情况下,简单地根据 A1 中的文件名构建参考字符串只会给你一个字符串,而不是L2019-1.xlsx A4的值。 You must put your reference string into the INDIRECT function to make it work.您必须将引用字符串放入INDIRECT函数中才能使其工作。

=INDIRECT("'C:\podatki\Finance\Sp\Predloge\["&A1&"]Sheet1'!$A$4")

Be aware that INDIRECT is a volatile function, so excessive use of it might slow down your calculation.请注意INDIRECT是一个易变的函数,因此过度使用它可能会减慢您的计算速度。

In order for that solution to work, the file you are referencing to ( L2019-1.xlsx ) must be open.为了使该解决方案起作用,您引用的文件 ( L2019-1.xlsx ) 必须打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM