简体   繁体   English

引用每天更改的文件/ Excel

[英]Reference a file that changes daily / Excel

Before I jump into a VBA solution, I wanted to know if it was possible to update a filename of a closed workbook I am referencing. 在进入VBA解决方案之前,我想知道是否可以更新我正在参考的封闭工作簿的文件名。

The formula reads, 公式显示为

=SUMIF('L:path\\[filename - "&TEXT(WORKDAY(TODAY(),-1),"yyyymmdd")&".xlsx]Sheet'!$BF:$BF,"criteria",'L:path\\[filename - "&TEXT(WORKDAY(TODAY(),-1),"yyyymmdd")&".xlsx]Sheet'!$DX:$DX)

To clarify, the path the filename would look something like this, This is the filename - yyyymmdd.xlsb 要澄清的是,文件名的路径看起来像这样, This is the filename - yyyymmdd.xlsb

Someone at work said it's not possible to change the filename because it's a string. 有人在工作,因为它是一个字符串,所以无法更改文件名。 If that is the case could someone just expand on that a bit? 如果是这样的话,有人可以扩大一下吗?

You can't really. 你真的不能。 If you have "Book1.xls" and "Book2.xls", what you can do it put this formula in book1: 如果您有“ Book1.xls”和“ Book2.xls”,可以执行以下操作将此公式放入book1中:

=MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,FIND("]", CELL("filename",A1))-FIND("[",CELL("filename",A1))-1) = MID(CELL(“ filename”,A1),FIND(“ [”,CELL(“ filename”,A1))+ 1,FIND(“]”,CELL(“ filename”,A1))-FIND(“ [ “,CELL(” filename“,A1))-1)

This will return the name (only) of Book1. 这将返回Book1的名称(仅)。 You could then reference that cell from Book2. 然后,您可以从Book2中引用该单元格。 HOwever, if you change Book1's name to something else, the reference will be broken and you will have to manually change the reference (pick the file from the update link manager). 但是,如果将Book1的名称更改为其他名称,则引用将被破坏,您将不得不手动更改引用(从更新链接管理器中选择文件)。 It seems excel uses absolute paths, including filename, to reference other workbook. 似乎excel使用绝对路径(包括文件名)来引用其他工作簿。 You would need to have a way to store a flexible reference to that workbook into Book2. 您将需要一种将对该工作簿的灵活引用存储到Book2中的方法。 But the only way to do is VBA. 但是唯一的方法是VBA。

Interestingly however you can do that: 有趣的是,您可以这样做:

  • Create a reference in book2 pointing to a cell in book1. 在book2中创建一个指向book1中单元格的引用。 You get the value of that cell in book2. 您在book2中获得该单元格的值。
  • Close everything. 关闭所有内容。
  • Open only book1, edit the referenced cell. 仅打开book1,编辑引用的单元格。 Close & save book1. 关闭并保存书1。
  • Book2, when you open it, will ask you if you want to update the link, and you can see the updated value even if book1 is still closed. 打开Book2时,它会询问您是否要更新链接,即使book1仍然关闭,您也可以看到更新后的值。

The other idea that I had was to use INDIRECT, like what is done there: using indirect function in Excel 我的另一个想法是使用INDIRECT,就像在那里所做的: 在Excel中使用间接函数

But it won't work for closed workbook and that's one of your requirements. 但这不适用于封闭的工作簿,这是您的要求之一。

So VBA it is. VBA就是这样。

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

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